How can I get 2nd and third column in tab delim file in bash?

落爺英雄遲暮 提交于 2019-11-30 12:57:15

问题


I want to use bash to process a tab delimited file. I only need the second column and third to a new file.


回答1:


cut(1) was made expressly for this purpose:

cut -f 2-3 input.txt > output.txt



回答2:


Cut is probably the best choice here, second to that is awk

awk -F"\t" '{print $2 "\t" $3}' input > out



回答3:


expanding on the answer of carl-norum, using only tab as a delimiter, not all blanks:

cut -d$'\t' -f 2-3 input.txt > output.txt

don't put a space between d and $



来源:https://stackoverflow.com/questions/6312564/how-can-i-get-2nd-and-third-column-in-tab-delim-file-in-bash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!