Go Back   The UNIX and Linux Forums > Top Forums > Emergency UNIX and Linux Support !! Help Me!!
google site



Emergency UNIX and Linux Support !! Help Me!! Post your urgent questions here for highest visibility. Posting a new thread to this forum requires Bits. We monitor this forum to help people with emergencies, but we do not guarantee response time or answers. This forum is "best effort" only. Members who reply to posts here receive a bonus of 1000 Bits per reply.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Search this Thread
  #1  
Old 12-30-2009
Registered User
 

Join Date: Oct 2008
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
awk- add columns and make new column and save as newfile

Hi,

I have file as below:

5 6 7
4 8 9
3 5 6

output needs to be another file with 4th column as $1+$2 and 5th column as $3+$4.

sample output file

5 6 7 11 18
4 8 9 12 21
3 5 6 8 14


Anybody have answer

Thanks in advance
Vasanth
Sponsored Links
  #2  
Old 12-30-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
 

Join Date: Dec 2008
Location: Sqrt[-e^(-2 i Pi)]
Posts: 3,925
Thanks: 2
Thanked 83 Times in 77 Posts
That's almost too simple:

Code:
$ cat test.txt
5 6 7
4 8 9
3 5 6
$ awk '{print $1,$2,$3,$1+$2,$1+$2+$3}' test.txt
5 6 7 11 18
4 8 9 12 21
3 5 6 8 14

  #3  
Old 12-30-2009
root cause analyst
 

Join Date: Nov 2008
Location: Amsterdam
Posts: 1,862
Thanks: 6
Thanked 105 Times in 101 Posts
Or :

Code:
awk '{$4=$1+$2;$5=$3+$4}1' infile

  #4  
Old 12-31-2009
Registered User
 

Join Date: Oct 2008
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
oh....

thanks...
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
help sum columns by break in first column with awk or sed or something. syadnom Shell Programming and Scripting 6 02-01-2009 04:23 AM
Convert two column data into 8 columns NickC Shell Programming and Scripting 8 06-28-2008 11:19 AM
Single column to multiple columns in awk astroDave Shell Programming and Scripting 2 03-27-2008 09:00 PM
How to check Null values in a file column by column if columns are Not NULLs Mandab Shell Programming and Scripting 7 03-15-2008 08:57 AM
Print last 4 columns (variable column #) Da_Duck UNIX for Dummies Questions & Answers 19 02-27-2004 09:33 AM



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