Sponsored Content
Full Discussion: help with add
Top Forums Shell Programming and Scripting help with add Post 302269407 by uwork72 on Wednesday 17th of December 2008 02:29:06 PM
Old 12-17-2008
help with add

Code:
$ cat file
x A 10 20 30
x B 5 10 12
x C 10 4 5
x D 10 3 6
x K 10 23 4
x M 5 7 0

Req o/p:

Code:
x A 15 30 42
x C 20 7 11
x K 15 30 4

Basically I want to add up 2 rows values as above.


I can sum the whole rows

Code:
$ awk '
{ for (i=3;i<=NF;++i) sum[i]+=$i; j=NF}
END {for (i=3;i<=j;++i) printf "%s%s",OFS,sum[i]}' file

 50 67 57

Please help to add two rows values as I mentioned in my req o/p above, thanks.
 

We Also Found This Discussion For You

1. Shell Programming and Scripting

How to add add some files together and then paste

How can you efficiently add pairs of files together and then paste those pairs, I have a climate computer at work which spits out temperatures and stuff out twice a day, one for the day-data and one for the night (basically). Every week I want to make a nice overview The text files are... (1 Reply)
Discussion started by: uwgandalf
1 Replies
COLORS(3)						   libbash colors Library Manual						 COLORS(3)

NAME
colors -- libbash library for setting tty colors. SYNOPSIS
colorSet <color> colorReset colorPrint [<indent>] <color> <text> colorPrintN [<indent>] <color> <text> DESCRIPTION
General colors is a collection of functions that make it very easy to put colored text on tty. The function list: colorSet Sets the color of the prints to the tty to COLOR colorReset Resets current tty color back to normal colorPrint Prints TEXT in the color COLOR indented by INDENT (without adding a newline) colorPrintN The same as colorPrint, but trailing newline is added Detailed interface description follows. Available colors: Green Red Yellow White The color parameter is non-case-sensitive (i.e. RED, red, ReD, and all the other forms are valid and are the same as Red). FUNCTIONS DESCRIPTIONS
colorSet <color> Sets the current printing color to color. colorReset Resets current tty color back to normal. colorPrint [<indent>] <color> Prints text using the color color indented by indent (without adding a newline). Parameters: <indent> The column to move to before start printing. This parameter is optional. If ommitted - start output from current cursor position. <color> The color to use. <color> The text to print. colorPrintN [<indent>] <color> The same as colorPrint, except a trailing newline is added. EXAMPLES
Printing a green 'Hello World' with a newline: Using colorSet: $ colorSet green $ echo 'Hello World' $ colorReset Using colorPrint: $ colorPrint 'Hello World'; echo Using colorPrintN: $ colorPrintN 'Hello World' AUTHORS
Hai Zaar <haizaar@haizaar.com> Gil Ran <gil@ran4.net> SEE ALSO
ldbash(1), libbash(1) Linux Epoch Linux
All times are GMT -4. The time now is 07:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy