adding a column at the end of the record


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers adding a column at the end of the record
# 1  
Old 11-07-2005
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
# 2  
Old 11-07-2005
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 11:32 AM.. Reason: changed the "while" to "for" loop
# 3  
Old 11-07-2005
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?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split column data if the table has n number of column's with some record

Split column data if the table has n number of column's with some record then how to split n number of colmn's line by line with records Table --------- Col1 col2 col3 col4 ....................col20 1 2 3 4 .................... 20 a b c d .................... v ... (11 Replies)
Discussion started by: Priti2277
11 Replies

2. UNIX for Dummies Questions & Answers

Match sum of values in each column with the corresponding column value present in trailer record

Hi All, I have a requirement where I need to find sum of values from column D through O present in a CSV file and check whether the sum of each Individual column matches with the value present for that corresponding column present in the trailer record. For example, let's assume for column D... (9 Replies)
Discussion started by: tpk
9 Replies

3. Shell Programming and Scripting

Appending CRLF to end of record

I need to append |\r\n (a pipe character and CRLF) at end of each record in Unix to all records where they are not already present. So first check for the presence of |\r\n and if absent append it else do nothing (3 Replies)
Discussion started by: abhilashnair
3 Replies

4. Shell Programming and Scripting

Adding end of line character in the last record

Need to add end of line character to last record in a fixed width file. When i take the record length of each line, for all the records it gives example like 200 except the last line as 199. Due to this my other script fails. Please help me on this. (4 Replies)
Discussion started by: Amrutha24
4 Replies

5. Shell Programming and Scripting

Need a ksh script for adding the space at the end of record in a flat file

Hi, I need a ksh script for the below requirement: i have a Delimited flat file with 200 records delimiter is '|~|' i need a script to insert space at the end if the record is ending with delimiter '|~|' if it didnt end with delimiter it should not append space. Example: ram|~|2|~| ... (16 Replies)
Discussion started by: srikanth_sagi
16 Replies

6. Shell Programming and Scripting

Adding additional column at the end

I have a file like below. The separator between reconds is ">" Each record consists of 2 numbers separated by a space. I want to write an awk script that copies the second number and puts it in the third column. :rolleyes: > 10 0 13 5.92346 16 10.3106 19 13.9672 22 16.9838 25... (5 Replies)
Discussion started by: kristinu
5 Replies

7. UNIX for Dummies Questions & Answers

End of record markers

I have a file with thousands of 80 character records. Unfortunately, there are no end of record characters, so any normal script commands that I've tried will process the entire file as one record. I.E. If I use grep to find the record that contains some specific value, I either get nothing... (3 Replies)
Discussion started by: Dave Miller
3 Replies

8. Shell Programming and Scripting

append a record at the end of a file

Hi all, i have to append a record at the end of the file(a file which is already with some records).how do i do?please help me? is there any way of doing this with "SED" command.i am not sure.plz help me on this. would appreciate your ideas!!!! bye rao. (3 Replies)
Discussion started by: raoscb
3 Replies

9. Shell Programming and Scripting

Adding spaces to record

Hi, I want to print spaces in a trailer record which is a single command. namely the unix command which i already have recs=`wc -l $TargetFileDir/myfile.txt|cut -c1-9`;export recs;echo 'PCPC.DXDINPT.FC0.INPUTFLE.PASS'`date +%Y%m%d``printf '%015d\n' $recs` >> $TargetFileDir/myfile1.txt I... (3 Replies)
Discussion started by: nvenkat010
3 Replies

10. Shell Programming and Scripting

splitting a record and adding a record to a file

Hi, I am new to UNIX scripting and woiuld appreicate your help... Input file contains only one (but long) record: aaaaabbbbbcccccddddd..... Desired file: NEW RECORD #new record (hardcoded) added as first record - its length is irrelevant# aaaaa bbbbb ccccc ddddd ... ... ... (1 Reply)
Discussion started by: rsolap
1 Replies
Login or Register to Ask a Question