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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Parsing problem Sushir03 Shell Programming and Scripting 3 04-18-2008 12:21 AM
Parsing problem Sushir03 Shell Programming and Scripting 2 04-16-2008 05:07 AM
Parsing problem Sushir03 Shell Programming and Scripting 1 04-16-2008 05:01 AM
Problem parsing line in file rlwilli Shell Programming and Scripting 2 09-02-2006 08:15 AM
parsing problem with script mike@freddiemac Shell Programming and Scripting 5 08-03-2006 12:06 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-29-2008
Registered User
 

Join Date: Jan 2008
Posts: 68
awk parsing problem

I need help with a problem that I have not been able to figure out.
I have a file that is about 650K lines. Records are seperated by
blank lines, fields seperated by new lines. I was trying to make
a report that would add up 2 fields and associate them with a CP.

example output would be something like this:

CP31
----
TCS 10 54087
TCS 342 35173

TOTAL 59260


CP33
----
TCS 8 48790
TCS 286 33614

TOTAL 82404

In a nutshell I have to sum up the first 2 fields of EDM blocks and WRC
blocks and then associate them with what TCS & CP they belong to. I would like
to use AWK, and was trying to use arrays, but with no luck. Maybe multi-
dimensional, have not had any experiance with these. Any help would be very
much appreciated.

Thanks in advance.

I attached a txt doc of partial file. I hope this makes sense.
Attached Files
File Type: txt HELP rev1.txt (8.6 KB, 9 views)

Last edited by timj123; 02-02-2008 at 08:20 AM.
Reply With Quote
Forum Sponsor
  #2  
Old 01-29-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milano, Italia/Варна, България
Posts: 1,933
Quote:
Originally Posted by timj123 View Post
[...]
example output would be something like this:
[...]
Could you post sample input data?

Edit: Where is the attachment?
Reply With Quote
  #3  
Old 01-29-2008
Registered User
 

Join Date: Jan 2008
Posts: 68
sorry, I think I had a error when I first tried to attach file. Thanks in advance
Reply With Quote
  #4  
Old 01-30-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milano, Italia/Варна, България
Posts: 1,933
Code:
awk '{printf "%s\n----\n%s %s %s\n%s %s %s\n\nTOTAL %d\n\n\n",
$1,$95,$96,$98+$99,$179,$180,$182+$183,$98+$99+$182+$183
}' RS= filename
I think you meant TOTAL 89260 and not TOTAL 59260 for
the first record.

Use nawk or /usr/xpg4/bin/awk on Solaris.
Reply With Quote
  #5  
Old 02-01-2008
Registered User
 

Join Date: Jan 2008
Posts: 68
radoulov,
first of all thanks a lot for looking at this for me, unfortunantely it is not working for me, it is my fault, I don't believe I was clear enough. The file is big and I don't want ALL the fields summed up, just CP fields and the associated TCS fields with the first two fields summed up. I hope this is clear???
Please let me know, because I have not gotten anywhere with this. Thanks
I can post more of the file if this will help.
Reply With Quote
  #6  
Old 02-02-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milano, Italia/Варна, България
Posts: 1,933
Code:
awk '/^CP/{printf "%s\n----\n%s %s %s\n%s %s %s\n\nTOTAL %d\n\n\n",
$1,$95,$96,$98+$99,$179,$180,$182+$183,$98+$99+$182+$183
}' RS= filename

If the above code doesn't work, post a bigger sample from your datafile.
Reply With Quote
  #7  
Old 02-02-2008
Registered User
 

Join Date: Jan 2008
Posts: 68
radoulov,
thanks again for looking at this, I attached a bigger example of input file Rev1, might have to open wider than 80 columns, and at the bottom of file I put desired output. I think I explained what I needed more clearly and I have reached my limit on what I can do in awk with this one and appreciate any help with this.

thanks in advance.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:57 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0