字符串后的grep特定数字

时间:2016-05-16 01:09:11

标签: bash shell grep

所以我现在正在尝试为gptfdisk创建一个脚本,我需要获得"分区唯一的GUID"。这是我得到的输出:

Partition GUID code: 48465300-0000-11AA-AA11-00306543ECAC (Apple HFS/HFS+)
Partition unique GUID: 677EDC3D-8AB1-458F-B849-F8B609339391
First sector: 352676 (at 1.3 GiB)
Last sector: 3899397 (at 14.9 GiB)
Partition size: 3546722 sectors (13.5 GiB)
Attribute flags: 0003000000000000
Partition name: 'Data'

最后我想要只有

677EDC3D-8AB1-458F-B849-F8B609339391

我将如何做到这一点?

3 个答案:

答案 0 :(得分:1)

这样做:

sed -n '/unique GUID/{s/.* GUID: //p}' your_file

或者如果你想输出一些输出:

command | sed -n '/unique GUID/{s/.* GUID: //p}'

答案 1 :(得分:0)

grep wih Perl regex:

grep -oP '(?<=unique GUID: ).*' file
677EDC3D-8AB1-458F-B849-F8B609339391

或使用两个grep操作:

grep 'unique GUID:' file | grep -o '[^[:blank:]]*$'
677EDC3D-8AB1-458F-B849-F8B609339391

答案 2 :(得分:0)

grep with awk -

cat file | grep 'Partition unique GUID' | awk -F: '{print $2}'