linux - 从标准输出中获取输出的最后 4 个字符

标签 linux bash shell character

我有一个正在运行并使用的脚本

lspci -s 0a.00.1 

这会返回

0a.00.1 usb controller some text device 4dc9

我想将最后 4 个字符内联,这样

lspci -s 0a.00.1 | some command to give me the last 4 characters. 

最佳答案

tail 怎么样,带有 -c 开关。例如,要获取“hello”的最后 4 个字符:

echo "hello" | tail -c 5
ello

请注意,我使用了 5 (4+1),因为 echo 添加了换行符。正如下面 Brad Koch 所建议的那样,使用 echo -n 来防止添加换行符。

关于linux - 从标准输出中获取输出的最后 4 个字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9219964/

相关文章:

linux - 什么时候使用虚拟内存是个坏主意?

linux - 在目录中迭代以在 linux 中备份 sqlite 表

python - 使用 SIGINT 终止程序会使我的 shell 无法使用,为什么?

bash - 收到错误 EOF : Command no found when using ssh

linux - 为什么循环内变量递减不返回成功状态代码?

mysql - Bash mysql错误处理锁定表

linux - 使用自动键循环浏览网页浏览器选项卡

linux - vim问题,我将其删除

C - 通过调用 printf?y 修复了 SDL 不一致的帧速率和屏幕垃圾

shell - 命令行工具的使用语句中打印的参数顺序是否有标准?