codehacker
codehacker

Reputation: 401

Print a column from Unix file

I have a unix file something like this

Name : abc
Name : def
Value : 123
Value_old : 456

I want to print abc,def,123,456 only.I am using awk -F'' '{print $3}' file but it is returning incorrect results.

Upvotes: 0

Views: 97

Answers (4)

tso
tso

Reputation: 4914

change delimiter:

awk -F": " '{print $2}' filename

Upvotes: 0

codehacker
codehacker

Reputation: 401

awk '{print $3}' file  

did the work.

Upvotes: 0

Kent
Kent

Reputation: 195029

awk -F'' '{print $3}'

won't work.

  • -F is delimiter, here obviously, it should be :
  • $3 means column 3, in your input, there are only two columns

So it should be awk -F':' '{print $2}'

There are many ways to get your input, like cut in the other answer.

Also, grep:

grep -o '[^:]*$'

sed:

sed 's/[^:]*://'

Upvotes: 1

izissise
izissise

Reputation: 943

You can use cut:

cut -d':' -f2

Upvotes: 3

Related Questions