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

前端 未结 3 1731
旧时难觅i
旧时难觅i 2020-12-29 03:01

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

相关标签:
3条回答
  • 2020-12-29 03:41

    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 $

    0 讨论(0)
  • 2020-12-29 03:44

    cut(1) was made expressly for this purpose:

    cut -f 2-3 input.txt > output.txt
    
    0 讨论(0)
  • 2020-12-29 03:54

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

    awk -F"\t" '{print $2 "\t" $3}' input > out
    
    0 讨论(0)
提交回复
热议问题