根据列中的特定单词删除特定行

Fr0*_*ght 1 bash tsv

我的制表符分隔的文件非常大,我需要删除在特定列中出现“ TelePacific”一词的所有行。在这种情况下,TelePacifc所在的所有行均在第4列中。这是一个示例输入文件:

7/18/13 10:06   0:00:09 TelePacific random person DEREK         9256408665  random company
7/18/13 10:07   0:00:21 TelePacific random person DEREK         9256408665  random company
7/18/13 10:10   0:19:21 TelePacific random person DEREK         9256408665  random company
7/18/13 10:39   0:01:07 random person       107  
7/18/13 11:02   0:01:41 random person Gilbert       107 TelePacific
7/18/13 12:17   0:00:42 random person Gilbert       107 TelePacific
7/18/13 13:35   0:00:41 random person Gilbert       107 TelePacific
7/18/13 13:44   0:12:30 TelePacific ADKNOWLEDGE     8169311771  random company
7/18/13 14:46   0:19:48 TelePacific TOLL FREE CALL  8772933939  random company
7/15/13 10:09   0:01:27 random person Esquivel      272 TelePacific
7/15/13 10:16   0:00:55 random person Esquivel      272 TelePacific
7/15/13 10:59   0:00:51 random person Esquivel      272 TelePacific
7/15/13 11:01   0:01:09 random person Esquivel      272 TelePacific
Run Code Online (Sandbox Code Playgroud)

anu*_*ava 5

使用grep -v

grep -v "\bTelePacific\b" file > output && mv output file
Run Code Online (Sandbox Code Playgroud)

或使用awk:

awk '$4 != "TelePacific"' file > output && mv output file
Run Code Online (Sandbox Code Playgroud)

  • +1表示\ b(“匹配单词边界”),因此您只匹配_word_“ TelePacific”而不是“ FooTelePacific”或“ TelePacificFoo”。 (2认同)