BASH:从标准输出,在线获取最后4个字符输出 [英] BASH : Get the last 4 characters of output from Standard Out, Inline
本文介绍了BASH:从标准输出,在线获取最后4个字符输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在运行和脚本使用
lspci的-s 0a.00.1
这将返回
0a.00.1 USB控制器一些文字设备4dc9
我要得到那些最后4个字符内联,这样
lspci的-s 0a.00.1 |一些命令来给我最后4个字符。
解决方案
如何尾
,用 -c
开关。例如,为了获得最后4个字符的你好:
回声你好|尾-c 5
ELLO
请注意,我用5(4 + 1),因为一个换行符是由添加回声
。正如布拉德·科赫以下建议,使用回声-n
来prevent换行符被添加。
I have a script that is running and uses
lspci -s 0a.00.1
This returns
0a.00.1 usb controller some text device 4dc9
I want to get those last 4 characters inline such that
lspci -s 0a.00.1 | some command to give me the last 4 characters.
解决方案
How about tail
, with the -c
switch. For example, to get the last 4 characters of "hello":
echo "hello" | tail -c 5
ello
Note that I used 5 (4+1) because a newline character is added by echo
. As suggested by Brad Koch below, use echo -n
to prevent the newline character from being added.
这篇关于BASH:从标准输出,在线获取最后4个字符输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文