The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
/etc/utmp file does not get updated with boot up details jyoti_mil UNIX for Advanced & Expert Users 1 06-11-2007 10:41 AM
logging SFTP details in a log file... santy UNIX for Dummies Questions & Answers 4 08-19-2006 02:05 PM
Read relevent details from Log File thinakarmani Shell Programming and Scripting 6 05-04-2006 03:48 AM
Details on the ls command and file types jacob358 UNIX for Dummies Questions & Answers 4 07-26-2005 12:12 PM
What file contains boot up init details? emplate HP-UX 4 05-04-2005 09:09 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-21-2008
bp_vardhaman bp_vardhaman is offline
Registered User
  
 

Join Date: Mar 2008
Location: Hyderabad,India
Posts: 12
i want to extract details for particular file

Hi i have following file

uuid ( RO) : 62701790-60da-dd9a-669d-a563aac1c435
host-uuid ( RO): 5f3f668d-a7c7-4e5f-a4a6-6e90fafb50ed
sr-uuid ( RO): 62103d07-e0aa-acf3-2d9f-414ad3377bd0
device-config (MRO): location: /dev/xapi/block
currently-attached ( RO): true


uuid ( RO) : 99158eac-8cce-39bd-4893-8576e7f18234
host-uuid ( RO): 5f3f668d-a7c7-4e5f-a4a6-6e90fafb50ed
sr-uuid ( RO): 3a1ff5ac-ed95-1deb-da89-ebc3459d0ae8
device-config (MRO): port: 3260; SCSIid: 149455400000000000000000001000000710300000d000000; target: 10.0.71.71; targetIQN: iqn.2001-04.com.example:storage.disk2.sys1.xyz
currently-attached ( RO): true


uuid ( RO) : 4a65094e-8e85-46e6-2c68-0987fe14decd
host-uuid ( RO): 5f3f668d-a7c7-4e5f-a4a6-6e90fafb50ed
sr-uuid ( RO): 655ad503-1a5f-1221-9181-9a5fb37cb672
device-config (MRO): location: /dev/xapi/cd
currently-attached ( RO): true


uuid ( RO) : a871cc47-185a-7886-5e7f-e2e6c0fb18e0
host-uuid ( RO): 5f3f668d-a7c7-4e5f-a4a6-6e90fafb50ed
sr-uuid ( RO): db6cece4-4847-ae2f-2b0b-f3901697e2b3
device-config (MRO): device: /dev/sdd
currently-attached ( RO): true


uuid ( RO) : 26c74e8b-d931-70a5-11b7-2f36262d116a
host-uuid ( RO): 5f3f668d-a7c7-4e5f-a4a6-6e90fafb50ed
sr-uuid ( RO): 762f3b74-aab9-8f7f-887d-15c1886314e0
device-config (MRO): device: /dev/sdc
currently-attached ( RO): true


so the file is still big now my question is i want to extract the UUID of (RO) of the any device if i pass as argument like "/dev/sdc" then it should pass me that particular uuid (RO) as "26c74e8b-d931-70a5-11b7-2f36262d116a" so can anybody tells wht exact command ? i trdied with awk and grep still not able to reach the final.

Thanks
  #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,864
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.
  #3 (permalink)  
Old 08-21-2008
bp_vardhaman bp_vardhaman is offline
Registered User
  
 

Join Date: Mar 2008
Location: Hyderabad,India
Posts: 12
Really not following here can i know what does mean of $3 here? can you give another trick if u know?
Thanks
  #4 (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,864
$3 should be the uuid, but maybe it should be $NF (the last field in the line). Try that instead.
  #5 (permalink)  
Old 08-21-2008
bp_vardhaman bp_vardhaman is offline
Registered User
  
 

Join Date: Mar 2008
Location: Hyderabad,India
Posts: 12
i want now include in script rather just want to try from Command line like this

cat dev.txt | awk '/^uuid/ { uuid=$3 } /^device-config/ && $NF == '/dev/sdc' { print uuid }'

But nothing it displaying
  #6 (permalink)  
Old 08-21-2008
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,116
Code:
awk '/^uuid/ { uuid=$3 } /^device-config/ && $NF == "/dev/sdc" { print uuid }' dev.txt
  #7 (permalink)  
Old 08-21-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,859
Another way is to set the field separator to ": "
Code:
awk -F": " '$1 ~ /^uuid/ { uuid=$2 };  $1 ~ /^device-config/ && $3 == "/dev/sdc" { print uuid }'  dev.txt
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 04:21 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0