从标准输出中获取输出的最后4个字符 [英] Get the last 4 characters of output from standard out

查看:86
本文介绍了从标准输出中获取输出的最后4个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在运行并使用

I have a script that is running and uses

lspci -s 0a.00.1 

这将返回

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. 

推荐答案

使用-c开关对tail进行操作.例如,要获取"hello"的最后4个字符:

How about tail, with the -c switch. For example, to get the last 4 characters of "hello":

echo "hello" | tail -c 5
ello

请注意,由于echo添加了换行符,因此我使用了5(4 + 1).如下面的Brad Koch所建议,请使用echo -n防止添加换行符.

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.

这篇关于从标准输出中获取输出的最后4个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆