如何在 bash 的 tab delim 文件中获得第二列和第三列?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6312564/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I get 2nd and third column in tab delim file in bash?
提问by RnD
I want to use bash to process a tab delimited file. I only need the second column and third to a new file.
我想使用 bash 来处理制表符分隔的文件。我只需要第二列和第三列到一个新文件。
回答by Carl Norum
回答by Fredrik Pihl
Cut is probably the best choice here, second to that is awk
Cut 可能是这里最好的选择,其次是 awk
awk -F"\t" '{print "\t" }' input > out
回答by vkersten
expanding on the answer of carl-norum, using only tab as a delimiter, not all blanks:
扩展 carl-norum 的答案,仅使用制表符作为分隔符,而不是所有空格:
cut -d$'\t' -f 2-3 input.txt > output.txt
don't put a space between d and $
不要在 d 和 $ 之间放置空格