regex - grep lines that contains only numbers or only letters characters until a delimiter -


kind of confusing title, let me explain. have tab delimited file contains lines in following format (columns delimited tab)

extra   573102|000473   zry|bc95624 missing abc|bc99000 missing 123456|001122 

i'd split file 4 different files, based on following logic:

  1. if line contains "extra" , numbers until "|", put line in file #1 (in above case, file #1 contain "extra 573102|000473").

  2. if line contains "extra" , letters until "|", put line in file #2 (in above case, file #2 contain "extra zry|bc95624").

  3. if line contains "missing" , numbers until "|", put line in file #3 (in above case, file #3 contain "missing abc|bc99000").

  4. if line contains "missing" , letters until "|", put line in file #4 (in above case, file #4 contain "missing 123456|001122").

i have no idea how combine text, tab character , regex accomplish above.

some dummy code:

regex1 = "^extra\h+\d+\|" # @ beginning of string / line in multiline mode # followed spaces , digits | character regex2 = "^extra\h+[a-za-z]+\|" # same letters regex3 = "^missing\h+\d+\|" regex4 = "^missing\h+[a-za-z]+\|"  if line matches regex1:     append file1 else if line matches regex2:     append file2 else if line matches regex3:     append file3 else if line matches regex4:     append file4 

see a demo on regex101.com


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -