输出文件的第二列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5985019/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 00:54:57 来源:igfitidea点击:
output the 2nd column of a file
提问by user678070
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
我如何输出第二列
采纳答案by James C
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 }'
回答by Roman
cut -d' ' -f2
awk '{print $2}'
cut -d' ' -f2
awk '{print $2}'
回答by ninjalj
Use cut with byte offsets:
使用带有字节偏移量的 cut :
cut -b 3
Use sed to remove trailing columns:
使用 sed 删除尾随列:
sed s/..//