I want to use bash to process a tab delimited file. I only need the second column and third to a new file.
Asked
Active
Viewed 5.4k times
3 Answers
86
cut(1)
was made expressly for this purpose:
cut -f 2-3 input.txt > output.txt

Carl Norum
- 219,201
- 40
- 422
- 469
15
Cut is probably the best choice here, second to that is awk
awk -F"\t" '{print $2 "\t" $3}' input > out

Fredrik Pihl
- 44,604
- 7
- 83
- 130
-
3the file had 2 million rows so i guess cut was good...thank you for your help – RnD Jun 10 '11 at 22:36
-
1`awk` comes in particularly handy when you want to change the order of columns. `cut` can't do that! – ostrokach Dec 21 '15 at 23:26
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 $

vkersten
- 131
- 1
- 5