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
Adding spaces to record nvenkat010 Shell Programming and Scripting 3 01-28-2008 10:24 AM
splitting a record and adding a record to a file rsolap Shell Programming and Scripting 1 08-13-2007 10:58 AM
Select Record based on First Column mgirinath Shell Programming and Scripting 8 07-15-2007 10:38 PM
FILE:Adding new column sandeep_hi Shell Programming and Scripting 2 06-09-2006 06:46 AM
Adding a column of numbers Khoomfire UNIX for Advanced & Expert Users 1 01-18-2006 01:55 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 11-07-2005
Registered User
 

Join Date: Oct 2005
Posts: 44
adding a column at the end of the record

hello.,

i have a .txt file.

inside the .txt file i have.,

/home/ss/cca.costco.transaction_date
/home/sk/cca.costco.transaction_date
/home/st/cca.costco.transaction_date
/home/sv/cca.costco.transaction_date

cca.costco.transaction_date is the file name.
inside the file there are some 100 records.
there are 28 columns. each field is comma
delimited.

i have to add a 29th column in each record
in each file. once it adds a number
in all the records in that file next it has
to go to the next file and add the number in 29th
columns in the next file.

it has to do it for all the files in that .txt file.

say i have to add a number
123 in the 1st file, 135 in 2nd file so on


this is my business requirement.

can anyone help me in doing this

thanks
Reply With Quote
Forum Sponsor
  #2  
Old 11-07-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,003
here's something to start with...
Code:
#!/bin/ksh
for fileName in $(< TXTfile.txt)
do
   sum=$(nawk -F, '{sum+=$29}END {print sum}' ${fileName})
   echo "file->[$fileName}] sum->[${sum}]"
done

Last edited by vgersh99; 11-07-2005 at 08:32 AM. Reason: changed the "while" to "for" loop
Reply With Quote
  #3  
Old 11-07-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,003
Quote:
Originally Posted by vgersh99
here's something to start with...
Code:
#!/bin/ksh
for fileName in $(< TXTfile.txt)
do
   sum=$(nawk -F, '{sum+=$29}END {print sum}' ${fileName})
   echo "file->[$fileName}] sum->[${sum}]"
done
well.. I got confused with your definition of "add a 29th column " - sorry about that.

What is the "value" of your new 29-th field?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:41 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