![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to add numbers | email-lalit | Shell Programming and Scripting | 8 | 05-12-2008 03:34 PM |
| need top 3 numbers | shary | Shell Programming and Scripting | 4 | 03-24-2008 10:58 PM |
| ksh and hex numbers | JamesByars | Shell Programming and Scripting | 2 | 01-15-2008 12:36 PM |
| How to add numbers? | pnxi | Shell Programming and Scripting | 7 | 09-11-2003 03:25 AM |
| Add some numbers! | TalkShowHost | Shell Programming and Scripting | 3 | 05-15-2002 09:28 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
how can i add two numbers
hi,
i am having one file which looks like the one below: ABC1 *** 1 4 ABC2 *** 7 12 ABC3 *** 0 34 ... i want to add the two numbers below each ABC and i want to find the largest out of this.. for example: in this case, 0+34=34 is the largest value and i want to get the result ABC3 into a variable. can anyone help me... thanks, Krips. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
There are cleaner ways....but this should work:
Code:
# cat infile
ABC1
***
1
4
ABC2
***
7
12
ABC3
***
0
34
# <infile paste - - - - - | awk '{print $3+$4,$1}' | sort -nr | sed q
34 ABC3
OR
# <infile paste - - - - - | awk '{print $3+$4,$1}' | sort -nr | sed q | cut -d" " -f2
ABC3
|
|
#3
|
||||
|
||||
|
Something like this:
Code:
v=$(awk 'END { print v }
($3 + $4) > m {
m = $3 + $4
v = $1
}' RS= file)
Last edited by radoulov; 07-11-2008 at 11:02 AM. Reason: too tired ... |
||||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|