awk parsing problem

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk parsing problem
# 1  
Old 01-29-2008
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:

TCS 10 54087
TCS 342 35173

TOTAL 59260

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 11:20 AM..
# 2  
Old 01-29-2008
Originally Posted by timj123
example output would be something like this:
Could you post sample input data?

Edit: Where is the attachment?
# 3  
Old 01-29-2008
sorry, I think I had a error when I first tried to attach file. Thanks in advance
# 4  
Old 01-30-2008
awk '{printf "%s\n----\n%s %s %s\n%s %s %s\n\nTOTAL %d\n\n\n",
}' 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.
# 5  
Old 02-01-2008
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  
Old 02-02-2008
awk '/^CP/{printf "%s\n----\n%s %s %s\n%s %s %s\n\nTOTAL %d\n\n\n",
}' RS= filename

If the above code doesn't work, post a bigger sample from your datafile.
# 7  
Old 02-02-2008
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk parsing problem

Hello fellow unix geeks, I am having a small dilemna trying to parse a log file I have. Below is a sample of what it will look like: MY_TOKEN1(group) TOKEN(other)|SSID1 MY_TOKEN2(group, group2)|SSID2 What I need to do is only keep the MY_TOKEN pieces and where there are multiple... (7 Replies)
Discussion started by: dagamier
7 Replies

2. Shell Programming and Scripting

Problem parsing

Hi, I want to fetch a text.Clipping. ... (5 Replies)
Discussion started by: protocomm
5 Replies

3. Shell Programming and Scripting

Complex text parsing with speed/performance problem (awk solution?)

I have 1.6 GB (and growing) of files with needed data between the 11th and 34th line (inclusive) of the second column of comma delimited files. There is also a lot of stray white space in the file that needs to be trimmed. They have DOS-like end of lines. I need to transpose the 11th through... (13 Replies)
Discussion started by: Michael Stora
13 Replies

4. Homework & Coursework Questions

Problem parsing input with awk

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I want add a line.For example:- 123456 1 1 0 1 1 0 1 0 0 0 1 5 8 0 12 10 25 its answer... (4 Replies)
Discussion started by: Arsh10
4 Replies

5. Shell Programming and Scripting

Parsing problem

Hello, I have a similar problem so I continue this thread. I have: | grep "RawData" |tr -s ' '|cut -d' ' -f 4|tr -d '%' So it supposed to return the percentage used of RawData FS: 80 (Want to use it in a alert script) However I also have a RawData2 FS so... (17 Replies)
Discussion started by: drbiloukos
17 Replies

6. Shell Programming and Scripting

Another parsing line awk or sed problem

Hi, After looking on different forums, I'm still in trouble to parse a parameters line received in KSH. $* is equal to "/AAA:111 /BBB:222 /CCC:333 /DDD:444" I would like to parse it and be able to access anyone from his name in my KSH after. like echo myArray => display 111 ... (1 Reply)
Discussion started by: RickTrader
1 Replies

7. Shell Programming and Scripting

Parsing Problem

Hi all, I am having problems parsing the following file: cat mylist one,two,three four five,six My goal is to get each number on a seperate line. one two three four five six I tried this command: sed -e 's/\,/^M/g' mylist (11 Replies)
Discussion started by: rob11g
11 Replies

8. Shell Programming and Scripting

Parsing problem

I need to parse a string which looks like "xyx","sdfsdf","asf_asdf" into var1="xyx" var2="sdfsdf" var3="asf_asdf" (3 Replies)
Discussion started by: Sushir03
3 Replies

9. Shell Programming and Scripting

Parsing problem

Hi, i need to parse a string which looks like this "xyz","1233","cm_asdfasdf" (2 Replies)
Discussion started by: Sushir03
2 Replies

10. Shell Programming and Scripting

Parsing problem

I need to separate out the contents in the string "xyz","1233","cm_asdfasdf" as xyz,1233,cm_asdfasdf Can anyone help me on this?? (1 Reply)
Discussion started by: Sushir03
1 Replies
Login or Register to Ask a Question