If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > File parsing returning block of output.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-23-04, 13:00
ontoes6 ontoes6 is offline
Registered User
 
Join Date: Jul 2004
Posts: 7
Question File parsing returning block of output.

Need to parse file which returns a block of output and not just that line.
Any direction is greatly appreciated.

Say Input file is of the following format:

NAME: SCAN1
CONDITION: if(....)
and (....)
ACTION: z=2

NAME: SCAN2
CONDITION: if (...)
ACTION: y=5
x=2

NAME: SCAN3
CONDITION: if(.....)
ACTION: x=4
y=2

NAME: SCAN4
CONDITION: if(.....)
ACTION: x=4


Need to write a script which parses the above file and gives me the block of what NAME string was provided.

e.g: If Input SCAN2, output should be :
NAME: SCAN2
CONDITION: if (...)
ACTION: y=5
x=2

Then need to look it so I can pull multiple block of whatever input I provide.

e.g:
SCAN2
SCAN4

provides me with the following output:

NAME: SCAN2
CONDITION: if (...)
ACTION: y=5
x=2

NAME: SCAN4
CONDITION: if(.....)
ACTION: x=4
Reply With Quote
  #2 (permalink)  
Old 07-23-04, 15:06
saurav101 saurav101 is offline
Registered User
 
Join Date: Oct 2003
Posts: 19
Hi
Are all your blocks separated by the single blank line . ?
Reply With Quote
  #3 (permalink)  
Old 07-23-04, 15:36
ontoes6 ontoes6 is offline
Registered User
 
Join Date: Jul 2004
Posts: 7
Quote:
Originally Posted by saurav101
Hi
Are all your blocks separated by the single blank line . ?

-----------------------
Hi Saurav... Nope. The only common thing is that i need everything from NAME to ACTN that defines a block.
Reply With Quote
  #4 (permalink)  
Old 07-23-04, 16:31
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
something to start with:

Code:
nawk -v name='SCAN2' $0 ~ ("^NAME:.*" name),/^ACTION/
nawk -v name='SCAN3' $0 ~ ("^NAME:.*" name),/^ACTION/
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
Reply With Quote
  #5 (permalink)  
Old 07-23-04, 17:01
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
to pull multiple blocks:
Code:
nawk -v name='(SCAN2|SCAN3)' $0 ~ ("^NAME:.*" name),/^ACTION/
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On