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

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

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 来防止添加换行符。

https://stackoverflow.com/questions/9219964/

相关文章:

linux - "In-source builds are not allowed"在 cmake

linux - 无法在 Ubuntu 16.04 中启动 Docker 服务

linux - 如何安排 tcpdump 在特定时间段内运行?

php - 使路径在 linux 和 Windows 上都有效

java - 无法创建Java虚拟机

linux - 如何将 bash 别名定义为多个命令的序列?

linux - 在 Ubuntu 中将目录添加到 PATH

linux - 须藤 : docker-compose: command not found

linux - 将时间跨度(以秒为单位)转换为 shell 中的格式化时间

linux - 当命令太长时,命令行会自动覆盖