Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I cut second column from the following list from terminal?

56    267  
57    235  
58    255  
59    283 
share|improve this question
up vote 4 down vote accepted

If the data is in a file called test.txt, awk '{ print $1 }' test.txt will do it.

share|improve this answer
This is for first column. – Radu Rădeanu Oct 23 '13 at 7:51
You'll want awk '{ print $2 }' file.txt instead, to get the 2nd column. – minerz029 Oct 23 '13 at 9:33
Yes. I know that. But the way I read the question I thought OP wanted to retain the first column. – user25656 Oct 23 '13 at 9:50

If the space between columns is a Tab character, then

cut -f 2

will do what you want. If they are spaces, then compress them to a single tab first:

tr -s \  \\t | cut -f 2
share|improve this answer

Try with:

sed -e "s/[[:space:]]\+/\t/g" filename | cut -f2

First command (sed) will replace all whitespace characters with one tab, and the result will be passed to the second command (cut) which will select the second field from each line.

See man cut and man sed for more info.

share|improve this answer

If your data was separated with a comma then your operation will be a lot easier:

kmcet@ubuntu:~$ cat data.txt
kmcet@ubuntu:~$ cut -d, -f1,1  data.txt
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.