2016-05-16 55 views
0

所以我目前正在嘗試爲gptfdisk創建一個腳本,並且我需要獲取「分區唯一GUID」。這是輸出我得到:grep字符串後的具體數字

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 

我將如何做到這一點?

+0

@BenjaminW。我已經看過那篇文章,儘管答案沒有完成我所需要的。 – TheOnlyGermanGuy

+0

'grep -oP'(?<=^Partition unique GUID:)。*'infile'如何工作? –

+0

Perl在我的grep版本中不受支持 – TheOnlyGermanGuy

回答

1

這樣做:

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

,或者如果你想管一些輸出做:

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

grep的王氏Perl的正則表達式:

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

或者使用兩個grep操作:

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

grep的使用awk -

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

+0

貓的無用用途。 – Jahid