![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. Last edited by timj123; 02-02-2008 at 08:20 AM. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Could you post sample input data?
Edit: Where is the attachment? |
|
#3
|
|||
|
|||
|
sorry, I think I had a error when I first tried to attach file. Thanks in advance
|
|
#4
|
||||
|
||||
|
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
the first record. Use nawk or /usr/xpg4/bin/awk on Solaris. |
|
#5
|
|||
|
|||
|
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. |
|
#6
|
||||
|
||||
|
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. |
|
#7
|
|||
|
|||
|
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. |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|