If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > adding a column at the end of the record

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-07-05, 10:10
pavan_test pavan_test is offline
Registered User
 
Join Date: Oct 2005
Posts: 45
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
  #2 (permalink)  
Old 11-07-05, 11:42
ducasio ducasio is offline
Registered User
 
Join Date: Aug 2004
Location: Rome, Italy
Posts: 81
Smile

try this:

---------------------------------
for i in `cat a.txt`
do
echo "Insert the value you want to add as the last column to the file $i : "
read col
awk -v var=$col '{printf $0 FS var "\n"}' $i >$i.new
done
-----------------------------------


bye,
ducasio
Reply With Quote
Reply

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On