The UNIX and Linux Forums  

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
Split a paragraph Sekar1 UNIX for Dummies Questions & Answers 3 06-05-2008 01:35 PM
Extract a paragraph capri_drm Linux 2 06-04-2008 04:01 PM
help, using awk to get paragraph kunimi Shell Programming and Scripting 6 06-04-2008 07:56 AM
extracting last paragraph from a text uvrakesh Shell Programming and Scripting 1 04-24-2007 06:36 AM
Bold the paragraph caprikar Shell Programming and Scripting 3 12-22-2003 06:44 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-23-2008
daveisme daveisme is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 39
searching for info in paragraph

I need to capture data from a paragraph list and am not sure how to get my data. I created a file from a tapeutil command which has many entries 1 entry is posted below
;
Slot Address 1025
Slot State ..................... Normal
ASC/ASCQ ....................... 0000
Media Present .................. Yes
Robot Access Allowed ........... Yes
Source Element Address Valid ... No
Media Inverted ................. No
Volume Tag ..................... 00001

I want to search for the volume tag # 00001 but I want to capture the Slot Address # 1025. Basically I want to search a file for tape 0001 and get a return of Slot Address 1025.
  #2 (permalink)  
Old 10-23-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Question what do records 1 & 3 look like?

Do they follow the same pattern? As in...

Slot Address 1024
Slot State ..................... Normal
ASC/ASCQ ....................... 0000
Media Present .................. Yes
Robot Access Allowed ........... Yes
Source Element Address Valid ... No
Media Inverted ................. No
Volume Tag ..................... 00011
Slot Address 1025
Slot State ..................... Normal
ASC/ASCQ ....................... 0000
Media Present .................. Yes
Robot Access Allowed ........... Yes
Source Element Address Valid ... No
Media Inverted ................. No
Volume Tag ..................... 00001

Slot Address 1026
Slot State ..................... Normal
ASC/ASCQ ....................... 0000
Media Present .................. Yes
Robot Access Allowed ........... Yes
Source Element Address Valid ... No
Media Inverted ................. No
Volume Tag ..................... 00002
  #3 (permalink)  
Old 10-23-2008
rubin's Avatar
rubin rubin is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2007
Posts: 321
Quote:
Originally Posted by daveisme View Post
...
Slot Address 1025
Slot State ..................... Normal
ASC/ASCQ ....................... 0000
Media Present .................. Yes
Robot Access Allowed ........... Yes
Source Element Address Valid ... No
Media Inverted ................. No
Volume Tag ..................... 00001

...Basically I want to search a file for tape 0001 and get a return of Slot Address 1025.


Code:
tag=00001

awk -v t="$tag" '/Volume Tag/ && $NF==t {print s} /Slot Address/ {s=$0}' file

Output


Code:
Slot Address 1025

  #4 (permalink)  
Old 10-24-2008
daveisme daveisme is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 39
follow up for joey

Yes the records look just as you specified. The follow the same pattern.
  #5 (permalink)  
Old 10-24-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink OK, here goes


Code:
> cat file301
Slot Address 1024
Slot State ..................... Normal
ASC/ASCQ ....................... 0000
Media Present .................. Yes
Robot Access Allowed ........... Yes
Source Element Address Valid ... No
Media Inverted ................. No
Volume Tag ..................... 00011
Slot Address 1025
Slot State ..................... Normal
ASC/ASCQ ....................... 0000
Media Present .................. Yes
Robot Access Allowed ........... Yes
Source Element Address Valid ... No
Media Inverted ................. No
Volume Tag ..................... 00001
Slot Address 1026
Slot State ..................... Normal
ASC/ASCQ ....................... 0000
Media Present .................. Yes
Robot Access Allowed ........... Yes
Source Element Address Valid ... No
Media Inverted ................. No
Volume Tag ..................... 00002

> cat file301 | sed "s/^Slot Address/~&/" | tr -s "." | tr "\n" " " | tr "~" "\n" | grep "Volume Tag . 00001" | cut -d " " -f3
1025

> cat file301 | sed "s/^Slot Address/~&/" | tr -s "." | tr "\n" " " | tr "~" "\n" | grep "Volume Tag . 00011" | cut -d " " -f3
1024

> cat file301 | sed "s/^Slot Address/~&/" | tr -s "." | tr "\n" " " | tr "~" "\n" | grep "Volume Tag . 00002" | cut -d " " -f3
1026

>

My logic explained:
want to place a '~' as a record marker
get rid of all those extra '.' characters
get rid of new-line characters (one big run-on record now)
turn the '~' into new-line characters (to again separate records)
grep for the desired text - note only one '.'
take the third field
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 07:54 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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