Remove extra characters and sum the columns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove extra characters and sum the columns
# 1  
Old 01-27-2011
Remove extra characters and sum the columns

I have data extracted like this:
Code:
A=%123% B=%456% C=%789%
A=%111% B=%222% C=%333%
A=%777% B=%888% C=%999%

Can someone please help me with a script to remove all the % signs and get the totals for A, B and C.
So output will be:
Code:
A=1368
B=666
C=2664

Thank you!

Last edited by Franklin52; 01-28-2011 at 03:30 AM.. Reason: Please use code tags
# 2  
Old 01-27-2011
Something like this,
Code:
awk -F"[=%]" '{a+=$3;b+=$6;c+=$9} END{printf "A="a"\nB="b"\nC="c"\n"}' infile

# 3  
Old 01-27-2011
Cool! Just what I'm looking for. Thank you for the quick response. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Group by columns and add sum in new columns

Dear Experts, I have input file which is comma separated, has 4 columns like below, BRAND,COUNTRY,MODEL,COUNT NIKE,USA,DUMMY,5 NIKE,USA,ORIGINAL,10 PUMA,FRANCE,DUMMY,20 PUMA,FRANCE,ORIGINAL,15 ADIDAS,ITALY,DUMMY,50 ADIDAS,ITALY,ORIGINAL,50 SPIKE,CHINA,DUMMY,1O And expected output add... (2 Replies)
Discussion started by: ricky1991
2 Replies

2. Shell Programming and Scripting

Evaluate 2 columns, add sum IF two columns satisfy the condition

HI All, I'm embedding SQL query in Script which gives following output: Assignee Group Total ABC Group1 17 PQR Group2 5 PQR Group3 6 XYZ Group1 10 XYZ Group3 5 I have saved the above output in a file. How do i sum up the contents of this output so as to get following output: ... (4 Replies)
Discussion started by: Khushbu
4 Replies

3. Shell Programming and Scripting

Request: How to Parse dynamic SQL query to pad extra columns to match the fixed number of columns

Hello All, I have a requirement in which i will be given a sql query as input in a file with dynamic number of columns. For example some times i will get 5 columns, some times 8 columns etc up to 20 columns. So my requirement is to generate a output query which will have 20 columns all the... (7 Replies)
Discussion started by: vikas_trl
7 Replies

4. UNIX for Dummies Questions & Answers

Replace extra Characters

The result of following command give me output which i further need to make some cosmetic change. grep -E "ERROR.*Session" wf_Load_25.log | awk '{print $14}' Output: : Expected Output: s_Load_XMLFile_Into_HashCustLoan_25 Please help, i am using bash (2 Replies)
Discussion started by: Ariean
2 Replies

5. Shell Programming and Scripting

Get the SUM of TWO columns SEPARATELY by doing GROUP BY on other columns

My File looks like: "|" -> Field separator A|B|C|100|1000 D|E|F|1|2 G|H|I|0|7 D|E|F|1|2 A|B|C|10|10000 G|H|I|0|7 A|B|C|1|100 D|E|F|1|2 I need to do a SUM on Col. 5 and Col.6 by grouping on Col 1,2 & 3 My expected output is: A|B|C|111|11100 (2 Replies)
Discussion started by: machomaddy
2 Replies

6. Shell Programming and Scripting

Evaluate 2 columns, add sum IF two columns match on two rows

Hi all, I know this sounds suspiciously like a homework course; but, it is not. My goal is to take a file, and match my "ID" column to the "Date" column, if those conditions are true, add the total number of minutes worked and place it in this file, while not printing the original rows that I... (6 Replies)
Discussion started by: mtucker6784
6 Replies

7. Shell Programming and Scripting

Remove first n characters from specific columns

I have a file like: s_20331 803 1 1 5 1:2=0.00000000 1:3=0.00000000 1:4=0.11111111 s_20331 814 1 1 5 1:2=0.00000000 1:3=0.12611607 1:4=0.00000000I would like to remove the four characters "x:x=" from all columns containing them (in my actual file, there are 15 total columns (i.e. columns... (1 Reply)
Discussion started by: pathunkathunk
1 Replies

8. UNIX for Dummies Questions & Answers

Removing extra new line characters

Hello, I have a text file that looks like: ABC123|some text|some more text|00001 00002 0003 0004 000019|000003|Item I have searched and found an example to remove the extra new line characters using grep and sed, but it (I think) assumes the lines start with a number and the... (5 Replies)
Discussion started by: c56444
5 Replies

9. UNIX for Dummies Questions & Answers

how to remove extra characters

Guys, I have a file that contains entries like this: LaxOrdID=19220288<8> LaxOrdID=19220288 I would like to remove <> and the values inside it anywhere its found. How? (2 Replies)
Discussion started by: DallasT
2 Replies

10. UNIX for Advanced & Expert Users

Remove new line characters if found between 1 to 10 columns

Hi, I have a file with ';' delimeter which has some new line characters. How can I delete the new line characters if they are found between 1 to 10 fields. Thanks (3 Replies)
Discussion started by: rudoraj
3 Replies
Login or Register to Ask a Question