output the 2nd column of a file

前端 未结 4 858
孤独总比滥情好
孤独总比滥情好 2020-12-30 01:15

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

相关标签:
4条回答
  • 2020-12-30 01:33
    1. cut -d' ' -f2
    2. awk '{print $2}'
    0 讨论(0)
  • 2020-12-30 01:39

    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}'
    
    0 讨论(0)
  • 2020-12-30 01:39
    cut -c2 listdir
    

    Here you can see for visualization:

    0 讨论(0)
  • 2020-12-30 01:41

    Use cut with byte offsets:

    cut -b 3
    

    Use sed to remove trailing columns:

    sed s/..//
    
    0 讨论(0)
提交回复
热议问题