nev*_*int 3 unix linux replace sed
鉴于此数据
34 foo
34 bar
34 qux
62 foo1
62 qux
78 qux
Run Code Online (Sandbox Code Playgroud)
我想将第二列的字符串替换为"",如果它是"qux".导致:
34 foo
34 bar
34
62 foo1
62
78
Run Code Online (Sandbox Code Playgroud)
你怎么用sed做到这一点?特别是数据非常大,约10 ^ 7行
pax*_*blo 15
我不会实际上做到这一点sed,因为这不是这项工作的最佳工具.awk只要有人提到列,该工具就是我的首选工具.
cat file | awk '$2 == "qux" { print $1 } $2 != "qux" { print $0 }'
Run Code Online (Sandbox Code Playgroud)
或最简单的形式:
cat file | awk '{ if ($2 == "qux") {$2 = ""}; print }'
Run Code Online (Sandbox Code Playgroud)
如果你必须使用sed:
cat file | sed 's/ *qux *$//'
Run Code Online (Sandbox Code Playgroud)
确保使用正确的空格(以上仅使用空格).