How to get the first column from the txt file using unix command?

Hi All,

I have the file like this (file name is : tem_text)

no Id name ccy
------- ---- ------------------- --------
7777 17 India Overseas Partners 500INR

I want to retreive the third colimn of from the above text file
if i use the basic awk command
cat tem_text | awk '{ print $3 }'
it will return only the
name
------
India
insetead of return the all details from the third column

name
---------------------
India Overseas Partners

Please advice me on this

Thanks
MPS

$3 is field 3 not row 3. Also no cat is needed.

awk 'NR == 3 {print}' tem_text

or shorter in sed

sed '3!d' tem_text

I think he wants the third column, not the third row, so $3 is right, but the third column has spaces in it. You can use this:

awk '{ sub("^[^ ]* [^ ]* ", "") ; sub(" [^ ]*$", "") ; print }'

The first sub() deletes the first two columns ([^ ]* => everything except a space; as long as possible, then a space and the whole thing again). The second sub() deletes the last column and everything in between (=> third column) is printed.

Oh, you are right of course.

sed:

sed 's/^[^ ]* [^ ]* \(.*\) [^ ]\{1,\}/\1/' tem_text

Or you can use sed

$ sed -e 's/\([^ ]*\) \([^ ]*\) \(.*\) \(.*$\)/\3/' tem_text
India Overseas Partners