![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Unix addition ( Row wise) | gauravgoel | Shell Programming and Scripting | 3 | 05-17-2007 04:27 AM |
| linux setup and addition config | chlawren | Linux | 3 | 02-05-2007 11:10 AM |
| floating point addition | ravi raj kumar | Shell Programming and Scripting | 8 | 12-22-2006 02:47 AM |
| Addition of numbers in unix | asinha63 | Shell Programming and Scripting | 3 | 03-14-2006 12:38 PM |
| suggested addition to forum rules | PxT | Post Here to Contact Site Administrators and Moderators | 1 | 10-31-2001 09:51 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Addition problem
Hello Seniors!!! I am trying to add to lines on a file which is delimited by character "|".
input.txt Quote:
output.txt Quote:
Thanks in advance. |
|
||||
|
You didn't say how many lines (records) there were, but this should work for any number of lines:
Code:
# echo "1|2|3|4|5
2|2|2|2|2" | awk '
{
n=split($0,a,"|")
for (i=1;i<=n;i++) { sum[i]=sum[i]+a[i] }
}END{
for (i=1;i<n;i++) { printf "%d|",sum[i] }
print sum[n]
}'
3|4|5|6|7
Last edited by gus2000; 12-08-2007 at 07:00 PM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|