标签: grep cut tail
我正在尝试抓取刚刚插入的驱动器的sda#。
sda#
tail -f /var/log/messages | grep sda:
返回:Mar 12 17:21:55 raspberrypi kernel: [ 1133.736632] sda: sda1
Mar 12 17:21:55 raspberrypi kernel: [ 1133.736632] sda: sda1
我想抓住标准输出的sda1部分,我该怎么做?
sda1
答案 0 :(得分:2)
我建议在GNU grep中使用它:
| grep -Po 'sd[a-z]+: \Ksd[a-z0-9]+$'
\ K:This sequence resets the starting point of the reported match. Any previously matched characters are not included in the final matched sequence.
请参阅:The Stack Overflow Regular Expressions FAQ