bash 剪切命令在 linux 上不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14742052/
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
Cut command not working on linux
提问by user2024264
I am trying this:
我正在尝试这个:
echo "This is test" | cut -f 1
echo "This is test" | cut -f 1
and it is not cutting anything, I get this:
它没有切割任何东西,我明白了:
This is test
This is test
回答by Warren Weckesser
Use a space as the delimiter in the cutcommand:
在cut命令中使用空格作为分隔符:
echo "This is test" | cut -f 1 -d ' '
The default delimiter is a tab. Take a look at the manpage for more details.
默认分隔符是制表符。有关更多详细信息,请查看联机帮助页。
回答by Mark Reed
By default, cutdoesn't split on space, only on tab. If you tell it to split on space, then it won't split on tab. Also, adjacent spaces or tabs will add empty fields to the set.
默认情况下,cut不按空间拆分,仅按选项卡拆分。如果您告诉它在空间上拆分,则它不会在选项卡上拆分。此外,相邻的空格或制表符会将空字段添加到集合中。
If you want to split on "any amount of any kind of whitespace", you're better off with awk:
如果您想拆分“任何数量的任何类型的空白”,最好使用awk:
echo "This is a test" | awk '{print }'
Also, you can replace echo...|with <<<in bash:
此外,您可以在 bash中用echo...替换:|<<<
awk '{print }' <<<"This is a test"

