如何使用 cut linux bash 剪切最后一个字段?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/53834476/
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-09-18 17:04:00  来源:igfitidea点击:

how to cut the last field using cut linux bash?

linuxbash

提问by Saif Marzougua

Hello everyone i want to know to cut the last field with separator : without knowing how many fields that i have any ideas please . is there any option for command cut .

大家好,我想知道用分隔符剪切最后一个字段:不知道有多少字段我有任何想法。命令 cut 是否有任何选项。

回答by Matias Barrios

Awk is the right tool for this. Try :

awk 是解决此问题的正确工具。尝试 :

ls -lh  | awk '{ print $NF }'

回答by Milan Dufek

You can revert the string and then print 1st character. Itself cutcan't work from backwards.

您可以还原字符串,然后打印第一个字符。本身切割不能从后工作。

echo "Your string ABC" | rev | cut -c 1