Linux 如何在shell中剪切字符串的第一列(可变长度)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14051902/
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-06 18:08:18 来源:igfitidea点击:
How to cut first column (variable length) of a string in shell
提问by Harsha K L
How to cut first column (variable length) of a string in shell ?
如何在shell中剪切字符串的第一列(可变长度)?
ex of string :
字符串的前:
23006 help.txt
23006 帮助.txt
I need 23006 as output
我需要 23006 作为输出
回答by anishsane
Many ways:
很多方法:
cut -d' ' -f1 <filename # If field separator is space
cut -f1 <filename # If field separator is tab
cut -d' ' -f1 <filename | cut -f1 # If field separator is space OR tab
awk '{print }' filename
while read x _ ; do echo $x ; done < filename
回答by Incognito
cut -d " " -f1 test.txt
where test.txt contains your input line
其中 test.txt 包含您的输入行
回答by honzajde
This one works for me
这个对我有用
cut -d' ' -f2-