The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
help needed nnayagam Shell Programming and Scripting 2 03-07-2008 06:34 AM
Little help needed. Netghost AIX 5 08-10-2006 03:29 PM
Help needed dsravan Shell Programming and Scripting 2 07-20-2006 10:37 AM
awk help needed. cskumar Shell Programming and Scripting 0 07-20-2006 08:24 AM
Sed help needed stevefox Shell Programming and Scripting 5 12-05-2005 01:44 AM

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 05-22-2006
Vikas Sood Vikas Sood is offline
Registered User
  
 

Join Date: May 2006
Posts: 32
Help needed in awk

Hi All,

I am trying to manipulate a file using awk in UNIX. My file "test_file" is structured as follows:

field1:field2:field3
field4:field5:field6
field7:field8:field9

My requirement is to calculate another field (which would be let's say sum of 2nd and third column and put as fourth column in this file). so that my final output would be

field1:field2:field3:fieldA
field4:field5:field6:fieldB
field7:field8:field9:fieldC

where fieldA=field2 + field3 and so on...

I have the following piece of code which I guess, is nowhere in the working condition right now:

while read line
do
echo $line | awk -F: 'BEGIN {OFS=":"}
{$4=$2 + $3 ; print $0}' >> new_test_file
done < test_file

I read somewhere that you can dynamically calculate variables in awk, so $4 would be dynamically calculated at the run time. Subsequently when i print $0 should contain the new calculated field too. But I guess that is not the case.

Can anybody look into above and help me out?

Thanks
  #2 (permalink)  
Old 05-23-2006
Vikas Sood Vikas Sood is offline
Registered User
  
 

Join Date: May 2006
Posts: 32
oops!! duplicate submission. Plz ignore this thread

I guess by mistake i submitted this twice. Plz ignore this one.
Thanks
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:48 PM.


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