![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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. |
|
|||||
|
Quote:
Code:
tag=00001
awk -v t="$tag" '/Volume Tag/ && $NF==t {print s} /Slot Address/ {s=$0}' file
Output Code:
Slot Address 1025 |
|
|||||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|