user678070
user678070

Reputation: 1425

output the 2nd column of a file

given a file with two columns, separatedly by standard white space

a b
c d
f g
  h

how do I output the second column

Upvotes: 21

Views: 63362

Answers (4)

Madinabonu Alisherova
Madinabonu Alisherova

Reputation: 61

cut -c2 listdir

Here you can see for visualization:

Upvotes: 1

Roman
Roman

Reputation: 13058

  1. cut -d' ' -f2
  2. awk '{print $2}'

Upvotes: 56

ninjalj
ninjalj

Reputation: 43688

Use cut with byte offsets:

cut -b 3

Use sed to remove trailing columns:

sed s/..//

Upvotes: 2

James C
James C

Reputation: 14149

Because the last line of your example data has no first column you'll have to parse it as fixed width columns:

awk 'BEGIN {FIELDWIDTHS = "2 1"} {print $2}'

Upvotes: 14

Related Questions