Extract UUID from string

Let’s use the blkid utility to find out information about our block device (hard disk sdb1 in this case) and extract the UUID  from it.

Here are two (of many various) possible options to do that.

This recognizes UUID only of “a81b3762-5c4d-4519-a7e3-2f12983d30d4” style:

  • blkid /dev/sdb1 | grep -P -o '[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}'

And this recognizes UUID of “a81b3762-5c4d-4519-a7e3-2f12983d30d4” and “40D401DED601E758” style:

  • blkid /dev/sdb1 | grep -P -o '(?<=UUID\=\")[-0-9A-Za-z]*(?=\" )'

					
Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s