iterative parsing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting iterative parsing
# 1  
Old 02-15-2011
iterative parsing

I have always struggled when parsing a file vertically vs. by line horizontally. Can't seem to get my head around the concept. Here again I need to convert vertical output to horizontal output.

original output
Code:
root@acuransx:bpplsched 2000-STAND3 -v -M acuransx -l
<2>bpplsched: INITIATING: version NetBackup 6.5 created: 2010042404
 
SCHED Yearly 0 1 15724800 8 0 0 0 *NULL* 0 0 0 0 0 0 -1 0 
SCHEDWIN 0 0 0 0 64800 54000 0 0 0 0 0 0 0 0
SCHEDRES *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL*
SCHEDPOOL *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL*
SCHEDRL 8 1 1 1 1 1 1 1 1 1
SCHEDFOE 0 0 0 0 0 0 0 0 0 0
SCHEDSG *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* 
 
SCHED Monthly 0 1 1209600 6 0 0 0 *NULL* 0 0 0 0 0 0 -1 0 
SCHEDWIN 0 0 0 0 64800 54000 0 0 0 0 0 0 0 0
SCHEDRES *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* 
SCHEDPOOL *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* 
SCHEDRL 6 1 1 1 1 1 1 1 1 1
SCHEDFOE 0 0 0 0 0 0 0 0 0 0
SCHEDSG *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* 
 
SCHED DAILY 1 1 86400 3 0 0 0 *NULL* 0 0 0 0 0 0 -1 0 
SCHEDWIN 72000 46800 72000 46800 0 0 72000 46800 72000 46800 72000 46800 72000 46800
SCHEDRES *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* 
SCHEDPOOL *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* 
SCHEDRL 3 1 1 1 1 1 1 1 1 1
SCHEDFOE 0 0 0 0 0 0 0 0 0 0
SCHEDSG *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* 
 
SCHED Weekly 0 1 86400 2 0 0 0 *NULL* 0 0 0 0 0 0 -1 0 
SCHEDWIN 0 0 0 0 64800 54000 0 0 0 0 0 0 0 0
SCHEDRES *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL*
SCHEDPOOL *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* 
SCHEDRL 2 1 1 1 1 1 1 1 1 1
SCHEDFOE 0 0 0 0 0 0 0 0 0 0
SCHEDSG *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* 
<2>bpplsched: EXIT status = 0

SCHED to SCHEDSG represents one schedule. I need to map out each schedule horzintally
example:
Code:
Yearly 15724800 0 0 64800 0 0 0 0 SCHEDPOOL SCHEDRL SCHEDFOE SCHEDSG 
Monthly 1209600 0 0 64800 0 0 0 0 SCHEDPOOL SCHEDRL SCHEDFOE SCHEDSG 
DAILY 86400 72000 72000 0 72000 72000 72000 72000 SCHEDPOOL SCHEDFOE SCHEDRL SCHEDSG 
Weekly 86400 0 0 64800 0 0 0 0 SCHEDPOOL SCHEDRL SCHEDFOE SCHEDSG

Your assistance is greatly appreciated.

Last edited by Franklin52; 02-15-2011 at 10:26 AM.. Reason: Please use code tags, thank you
# 2  
Old 02-15-2011
Code:
# awk 'NR>2&&/^SCHED /{x=$2" "$5}/^SCHEDWIN/{x=x" "$2" "$4" "$6" "$8" "$10" "$12" "$14;print x" SCHEDPOOL SCHEDRL SCHEDFOE SCHEDSG"}' infile

Code:
Yearly 15724800 0 0 64800 0 0 0 0 SCHEDPOOL SCHEDRL SCHEDFOE SCHEDSG
Monthly 1209600 0 0 64800 0 0 0 0 SCHEDPOOL SCHEDRL SCHEDFOE SCHEDSG
DAILY 86400 72000 72000 0 72000 72000 72000 72000 SCHEDPOOL SCHEDRL SCHEDFOE SCHEDSG
Weekly 86400 0 0 64800 0 0 0 0 SCHEDPOOL SCHEDRL SCHEDFOE SCHEDSG

# 3  
Old 02-15-2011
That worked really well but how did it work. Please if you don't mind take the time to break it down for me. I would really like to understand this better.
# 4  
Old 02-15-2011
Alternatively:
Code:
awk 'NR>1{print $2,$5,$20,$22,$24,$26,$28,$30,$32,$42,$50,$61,$72}' RS= infile

# 5  
Old 02-15-2011
@Jouuuu

(condition){action}
for lines matching condition, actions are performed
NR>2 if the record number is more than 2 (that skip the first 2 lines)
&&/^SCHED / and the line start by the pattern SCHED<SPACE>
x=$2" "$5 put fields 2 and 5 separated by space into the variable x
/^SCHEDWIN/ if line start with pattern SCHEDWIN
x=x" "$2" "$4" "$6" "$8" "$10" "$12" "$14 concatenate the wanted field into the variable x
print x" SCHEDPOOL SCHEDRL SCHEDFOE SCHEDSG" Print x and concatenate the rest of the wanted string
@Scruti

Yes, i am still an awk noobzor


Smilie

Last edited by ctsgnb; 02-15-2011 at 01:21 PM..
This User Gave Thanks to ctsgnb For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

parsing

Can some body show me a sed command to remove everyhing upto a '/' and leave the rest of the line. cat data.out This is the directory /tmp/xxx/yy.ksh I only want to get the fullpath name /tmp/xxx.yy.ksh Thanks in advance to all who answer. (3 Replies)
Discussion started by: BeefStu
3 Replies

2. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

3. Shell Programming and Scripting

Iterative statement to cut values from a line

Hi I am new to shell scripting and trying to get values from a text file, I have a text file with values seperated with "|". like aga|120220090525|120220090525|120220090525|120220090530 bab|120220090530|120220090530|120220090535|120220090535|120220090535... (4 Replies)
Discussion started by: mannepalli
4 Replies

4. Shell Programming and Scripting

Parsing the data

Hi I need to parse the following data using shell script Table ----- stage4n_abc 48 stage4o_abcd 4 adashpg_abc_HeartBeat 1 stage4l_asc 168 Can anyone gimme the solution. I want each value to get stored in an array or variable and want the value to be greped from another file.... (1 Reply)
Discussion started by: Archana.Dheepan
1 Replies

5. Shell Programming and Scripting

Need help with some iterative file processing

Gurus - Please help with this urgent situation. I have the following problem to solve using a shell script: 1. There are about 13 files named CONTAINER_1.lst, CONTAINER_2.lst, CONTAINER_3.lst .....CONTAINER_13.lst 2. Each of these files contain about 8 lines (in most cases) containing... (1 Reply)
Discussion started by: inditopgun
1 Replies

6. Shell Programming and Scripting

Iterative operation

grep -o '\{1,3\}\.\{1,3\}\.\{1,3\}\.\{1,3\}' then how do i iterate the file names?? (19 Replies)
Discussion started by: ravis83
19 Replies

7. Shell Programming and Scripting

Perl parsing compared to Ksh parsing

#! /usr/local/bin/perl -w $ip = "$ARGV"; $rw = "$ARGV"; $snmpg = "/usr/local/bin/snmpbulkget -v2c -Cn1 -Cn2 -Os -c $rw"; $snmpw = "/usr/local/bin/snmpwalk -Os -c $rw"; $syst=`$snmpg $ip system sysName sysObjectID`; sysDescr.0 = STRING: Cisco Internetwork Operating System Software... (1 Reply)
Discussion started by: popeye
1 Replies

8. Shell Programming and Scripting

Need some help with parsing

I have a big xml file with little formatting in it. It contains over 600 messages that I need to break each message out in its own separate file. The xml file looks in the middle of it something like this: </Title></Msg><Msg><Opener> Hello how are you?<Title> Some says hello</Title><Body>... (3 Replies)
Discussion started by: quixoticking11
3 Replies

9. Shell Programming and Scripting

Parsing question

Hi Guys, I was wondering if you could help me out - I have a directory /home/users/datafiles/ which contain files "dat dd-mm-yy.xls" I am trying to write a script which does the following - (1) loops through all the files (2) retrieves the dd-mm-yy string and converts it into a... (12 Replies)
Discussion started by: muser
12 Replies

10. UNIX for Dummies Questions & Answers

parsing

Hi, I want to parse this file.... ( 0 , 0 ) =>heading1 ( 0 , 1 ) =>value1.1a ( 0 , 2 ) =>value2.1a ( 1 , 0 ) =>heading2 ( 1 , 1 ) =>value1.1b ( 1 , 2 ) =>value2.1b ( 2 , 0 ) =>heading3 ( 2 , 1 ) =>value1.1c ( 2 , 2 ) =>value2.1c ( 3 , 0 ) =>heading4 ( 3 , 1 ) =>value1.1d ( 3 , 2... (15 Replies)
Discussion started by: tungaw2004
15 Replies
Login or Register to Ask a Question