The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
POSIX way of getting columns in tty? otheus Shell Programming and Scripting 13 01-12-2009 10:31 AM
text in columns mierdatuti Shell Programming and Scripting 4 01-10-2009 08:38 AM
Row to Columns vskr72 UNIX for Dummies Questions & Answers 4 03-21-2007 09:53 AM
add columns with awk tonet Shell Programming and Scripting 4 06-21-2005 04:02 AM
printing columns cdunavent Shell Programming and Scripting 3 06-07-2003 12:31 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-09-2009
bogu0001 bogu0001 is offline
Banned
  
 

Join Date: Jan 2009
Posts: 32
how to get difference of two columns

hey guys i want to divide the 2nd column with the first column using any command of unix
help would be appreciated

input
set1
10
40
set2
12
60

output
2
20
  #2 (permalink)  
Old 02-09-2009
angheloko's Avatar
angheloko angheloko is offline
Registered User
  
 

Join Date: Jul 2008
Location: Philippines
Posts: 125
With a little help from the "Search" button:

http://www.unix.com/cfmgoogle.php?cx...sa=Search#1313
  #3 (permalink)  
Old 02-09-2009
bogu0001 bogu0001 is offline
Banned
  
 

Join Date: Jan 2009
Posts: 32
Addition of the values. Sorry not substraction this time

Thanq u
but my file is little bit complicated. all values of column 1 and 2 are in 2 seperate single cells!!!!!!

input
column1
0,9607,12887,24088,
column2
579,248,404,385

output
579,9855,13291,24473
  #4 (permalink)  
Old 02-09-2009
bogu0001 bogu0001 is offline
Banned
  
 

Join Date: Jan 2009
Posts: 32
sorry not subtraction , this time addition!!!!

!!!!!!!!!!!!!!!!!!!!!!!
  #5 (permalink)  
Old 02-09-2009
angheloko's Avatar
angheloko angheloko is offline
Registered User
  
 

Join Date: Jul 2008
Location: Philippines
Posts: 125
You can still use the little "Search" button, man. I found some threads similar with this one, but here goes:

Code:
awk 'BEGIN {FS=","} { for (i=1;i<=NF;i++) sum[i]=sum[i] + $i } END { for (i=1;i<=NF;i++) printf("%d,", sum[i]) }' foo
  #6 (permalink)  
Old 02-09-2009
bogu0001 bogu0001 is offline
Banned
  
 

Join Date: Jan 2009
Posts: 32
but its printing the input numbers as it is in output
I'm unable to get the result
Sorry for the trouble man
  #7 (permalink)  
Old 02-09-2009
angheloko's Avatar
angheloko angheloko is offline
Registered User
  
 

Join Date: Jul 2008
Location: Philippines
Posts: 125
Hmmm...Could you post sample input and output?

I got the ff:

Code:
$ cat foo
0,9607,12887,24088,
579,248,404,385

$ awk 'BEGIN {FS=","} { for (i=1;i<=NF;i++) sum[i]=sum[i] + $i } END { for (i=1;i<=NF;i++) printf("%d,", sum[i]) }' foo
579,9855,13291,24473,
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:11 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0