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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-22-2006
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
Reply With Quote
Forum Sponsor
  #2  
Old 05-22-2006
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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 03:47 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0