Jui*_*icy 3 terminal text-processing regular-expression cut columns
我有一个大文件,每行都有几列。我熟悉使用cut -f -d按编号选择特定列。
我检查了手册,cut似乎没有办法正则表达式匹配列。
我具体想做的是:
这个操作最方便的终端工具是什么?
编辑:
简化示例
x ID23 a b c hello1
x ID47 hello2 a b c
x ID49 hello3 a b hello4
x ID53 a b c d
Run Code Online (Sandbox Code Playgroud)
我想要的结果是:
ID23 hello1
ID47 hello2
ID49 hello3 hello4
Run Code Online (Sandbox Code Playgroud)
或者:
ID23 hello1
ID47 hello2
ID49 hello3 hello4
ID53
Run Code Online (Sandbox Code Playgroud)
详细说明给出的示例:
grep如有必要,我可以只为“你好”如果该行末尾的一个空格不会对您造成太大伤害:
$ awk '{for(i=1;i<=NF;i++) if(i==2 || $i~"hello") printf $i" ";print ""}' file
ID23 hello1
ID47 hello2
ID49 hello3 hello4
ID53
Run Code Online (Sandbox Code Playgroud)
这对“hello”字符串的位置没有任何假设。