How do i add horizontally??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How do i add horizontally??
# 8  
Old 04-03-2013
Quote:
Originally Posted by nikhil jain
hey balajesuri
I wanted individual rows total not the total of all the rows
This is the output I got:
71359
8607
8396
23789

Did you try the perl one-liner? What output did you get?
# 9  
Old 04-03-2013
This can be shorten some, by removing not needed ;, and simplify the sum
Code:
awk -F'[:,=]' '{c=$1; for (i=3;i<=NF;i+=2) {s+=$i} print c"="s}' file

or like this
Code:
awk -F'[:,=]' '{c=$1; for (i=3;i<=NF;i+=2) s+=$i; print c"="s}' file

# 10  
Old 04-03-2013
Thanks Jotne. Smilie So it should be,

Code:
awk -F'[:,=]' '{c=$1; for (i=3;i<=NF;i+=2) s+=$i; print c"="s; s=0}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sort two columns with alphanumeric values horizontally

Hi, I have a file like aa bb dmns|860 dmns|756 ee ff aa bb dmns|310 dmns|260 ee ff aa bb dmns|110 dmns|77 ee ff aa bb dmns|756 dmns|860 ee ff aa bb dmns|110 dmns|77 ee ff aa bb dmns|233 dmns|79 ee ff aa bb dmns|79 dmns|233 ee ff I want to sort the values in column3 and column4... (2 Replies)
Discussion started by: sammy777888
2 Replies

2. Shell Programming and Scripting

Lookup horizontally and vertically and calculate counts

Hello, Please help create the following report. I have a matrix - S1 S2 S3 S4 M1 AA AA TT - M2 AG AG AA GG M3 GG TT - - a first lookup table M3 chr7 4.456 M1 chr7 28.9 M2 chr8 129.678 a second lookup table S1 GGHBBGG/DEDD(@DCCD) (8 Replies)
Discussion started by: jianp83
8 Replies

3. Shell Programming and Scripting

Calculation of column both horizontally and vertically

Hi ALL I have this data ail,UTT,id1_0,COMBO,21,24,21,19 al,UTHAST,id1_0,COMBO,342,390,361,361 dmo,UTST,id1_0,COMBO,21,15,22,23 vne,UAST,id1_0,COMBO,345,372,390,393 I wan the sum of column 5,6,7 & 8 both horizontal and vertical. There is one more prob the column keeps on increasing... (9 Replies)
Discussion started by: nikhil jain
9 Replies

4. UNIX for Dummies Questions & Answers

[SOLVED] re-parse duplicate horizontally

I have a 2 column file. Column 1 is a road ID number. Column 2 is the date that the road surface condition was inspected. Some roads have been inspected only once, while some roads have been inspected multiple times. I would like to re-arrange the following example list: 1001 2001_01_01... (5 Replies)
Discussion started by: kenneth.mcbride
5 Replies

5. Shell Programming and Scripting

Sort each row (horizontally) in AWK or any

Hello, How to sort each row in a document with numerical values and with more than one row. Example Input data (file1.txt): 4 6 8 1 7 2 12 9 6 10 6 1 14 5 7 and I want the the output to look like this(file2.txt): 1 4 6 7 8 2 6 9 10 12 1 5 6 7 14 I've tried sort -n file1.txt >... (12 Replies)
Discussion started by: joseamck
12 Replies

6. Shell Programming and Scripting

Append the output data horizontally

Hi experts i have a simple script that fetches the count from different servers and inserts ahead of server name like below servera,1 serverb,25 serverc,35 what i want to do is now when i run this script next day i want that output to be next to the earlier one like below and if possible... (5 Replies)
Discussion started by: raj2989
5 Replies

7. Shell Programming and Scripting

Need help in reading a file horizontally and printing vertically

Hi Every body, I have file which has enttries, with each 5 entries as a set of entries, I would like to read the file (line by line) and print five entries of a set vertically, the next entry should come in the next line. Example: cat sample_file I am a Unix Adminsitrator new to shell... (6 Replies)
Discussion started by: aruveiv
6 Replies

8. Shell Programming and Scripting

merge two files horizontally

Hi all, I have two files -- one with 1024 lines and another with 2048 lines. I want to merge them to create another file in such way that it takes 2 lines from file with 1024 lines and 4 from 2048 lines. I wrote a sample script and curious to see if there is a better way; i am sure there is,... (4 Replies)
Discussion started by: jakSun8
4 Replies

9. HP-UX

Combining files horizontally

I have 2 files, 1.txt and 2.txt which have the following format: 1.txt :451:1 :451:0 :451:1 and so on.. 2.txt :108:13897187 :108:90890789 :108:76476386 and so on.. I want to combine the files horizontally, I tried paste 1.txt 2.txt as well as cat but both of them are giving me... (3 Replies)
Discussion started by: anshuljain
3 Replies

10. UNIX for Advanced & Expert Users

Merging Two File Horizontally

I am trying to merge two large file horizontally using paste command. Every thing is working fine except for time. Its taking lot of time. Is there any effiecient way of doing the same thing or is there anyway by which I can improve its perfomance programatically? Thanks, Yeheya (1 Reply)
Discussion started by: yeheyaansari
1 Replies
Login or Register to Ask a Question