oe a
oe a

Reputation: 2280

How to cut part of grepped value

I am running this command in a shell script:

user@nas:~$ lsblk -o NAME,PARTUUID | grep 9bf22f69-05
└─sdi1             9bf22f69-05                                                                        9bf22f69-05

How do I use cut in the command to only give me the first part (sdi)?

Upvotes: 2

Views: 469

Answers (1)

hek2mgl
hek2mgl

Reputation: 157947

I would use the raw output format of lsblk with -r:

$ lsblk -roNAME,PARTUUID 
NAME PARTUUID
sda 
sda1 f56e224a-94e0-401b-9081-b19d4f43e001
sda2 b3907cd2-ee93-4c49-870e-13e9f3ab9b31
sda4 b8e25594-6e1c-4f35-aff7-474971137144
sda5 514cfde6-f765-4cb3-bb26-8c5136f874a8
sda7 c5f8194a-0f87-43eb-9b92-d24d293bbc93
sda8 11ee6409-c750-4023-9cb5-bf7f435509ad
sda8 cdb29b03-d91b-4b19-89e2-634a56826015

Now it is simple to obtain the block devices identifier using awk:

$ lsblk -roNAME,PARTUUID | awk '/b3907cd2/{print $1}'
sda4

Upvotes: 3

Related Questions