The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 08-21-2008
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,893
Many ways to do this... But it is a bit tricky.

Code:
find_uuid() {
  dev=$1
  awk '/^uuid/ { uuid=$3 } /^device-config/ && $NF == '$dev' { print uuid }' uuid-file
}

You'll need to change the filename (uuid-file) to the one you want (or empty for stdin). Then just do "find_uuid /dev/sdc" from the shell.

The trick is in realizing that awk is a series of pattern-script pairs, not just one. The first one is used to remember the most-recently seen uuid. The second prints it out when the device name matches.