regex - string match using awk -
I have a separate file from the tab that contains the rows:
field1 field2 field3 field4 field 5 Field 6 1 ABC 2 Words: Add, Word: Text String 2 XII 2 Remove Word: Change, Word: Modify Message String 3 Lmn 1 Word: Add Message Numeric 4 Cncn 2 Phone: Add, Phone: Remove Message Message Number 5 Lmn 2 words: add msg text I want to write an awk program / oneliner which I In the other words, it should be first filtered and then "add" or "remove" in field 4 and
field3 == 2 and field 4 and, 1 abc 2 words: add, word: remove text string 2 xyz 2: change, word: modify msg string 4 cncn 2 phone: add, phone: remove message numerical 5 lmn 2 words: Add msg msg They should be filtered in the second step
1 ABC 2 words: add, After: Remove the text string 4 cncn2 phone: add, phone: delete message numerical 5 lmn 2 words: add msg text I can get the first step right Use: < Code> cat test.tsv | Awk -F '\ t' '$ 3 == 2'
How do I match the substrings for the second part? Thanks in advance
You can match the fields using ~ : awk -F '\ t' '$ 3 == 2 & amp; Amp; $ 4 ~ / add Remove / 'filename will produce the desired result:
1 abc 2 words: add, word: text string 4 delete cnn 2 phone: add, phone : Remove the message numerical 5 LMN2 words: Add msg msg Excerpt from manual:
~! ~ Regular Expression Match, Disapproved Match Note: Do not use a continuous regular expression (/ foo /) on the left side of any ~ or ~ ~ on the right side only use one expression / foo / ~ exp means it (($ 0 ~ / foo /) ~ EXP). This is not usually the case with the intention of
Comments
Post a Comment