Need to append file name to all rows in in .csv file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to append file name to all rows in in .csv file
# 1  
Old 10-12-2006
Error Need to append file name to all rows in in .csv file

Hi ,

Can some one help in appending the file name to all the rows in .csv files the current work is like this.
This is adding a new line for file name,
I need to append file name to all lines in .csv


for i in `ls $filename*.csv`
do
echo "$i" > ./tmpfile
cat "$i" >> ./tmpfile
mv ./tmpfile "$i"
echo $i
sqlldr userid=$login control=.ctl data=$i log=/tmp/$i.log bad=/tmp/$i.bad
mv $i $destdir
done
exit 0

Last edited by Satyagiri; 10-12-2006 at 08:26 AM..
# 2  
Old 10-12-2006
You can try someyhing like that (assume ';' as field separator in the .csv files) :
Code:
for i in `ls $filename*.csv`
do
   awk -v OFS=';' '{print $0,FILENAME}' "$i" > ./tmpfile
   mv ./tmpfile "$i"
   echo $i
   sqlldr userid=$login control=.ctl data=$i log=/tmp/$i.log bad=/tmp/$i.bad
   mv $i $destdir
done
exit 0


Jean-Pierre.
# 3  
Old 10-12-2006
Sorry it doen't work as and loads the entire data in the first field
# 4  
Old 10-13-2006
Please give us an example of input data file, the result you need (file to be loaded with sqlldr) and the contents of your control file.


Jean-Pierre.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get duplicate rows from a csv file

How can i get the duplicates rows from a file using unix, for example i have data like a,1 b,2 c,3 d,4 a,1 c,3 e,5 i want output to be like a,1 c,3 (4 Replies)
Discussion started by: ggupta
4 Replies

2. Shell Programming and Scripting

Append spaces the rows to make it into a required fixed length file

I want to make a script to read row by row and find its length. If the length is less than my required length then i hav to append spaces to that paritucular row. Each row contains special characters, spaces, etc. For example my file contains , 12345 abcdef 234 abcde 89012 abcdefgh ... (10 Replies)
Discussion started by: Amrutha24
10 Replies

3. Shell Programming and Scripting

I want to append data to same .csv file.

I have a script which has to be scheduled to run 3 times a day. My script picks the required fields from logfile and stores the data in a.csv file. Sample data. my logfile contain: 0097A,0374D,100903,1519,00000606191 0097A,C88RA,100903,0724,00000606105 So the output of first execution... (3 Replies)
Discussion started by: shrima.pratima
3 Replies

4. Shell Programming and Scripting

Unix Script file to Append Characters before rows in file.

Hi Experts, I am working on HP-UX. I am new to shell scripting. I would like to have a shell script which will prefix: 1. "H|" before first row of my file and, 2. "T" for all other rows of the file. For Example - File before running the script 20100430|4123451810|218.50|TC 20100430 ... (4 Replies)
Discussion started by: phani333
4 Replies

5. Shell Programming and Scripting

changing csv file contents to file of rows

i have a file a.txt contents as 1,2,3,4,......etc...in a single line, i want to write to another file in rows as 1 2 3 4 5 can u help? i do not know the length of a.txt (4 Replies)
Discussion started by: pravfraz
4 Replies

6. Shell Programming and Scripting

How to append value at first line of CSV file using shell script?

I have an issue where I need to append a value at the last of the csv, I have created a shell script and it is appending the columns at the last but it is appending at all lines, and my requirement is specific to just append at the 1st line. Have a look and suggest, (7 Replies)
Discussion started by: anujrichhariya
7 Replies

7. Shell Programming and Scripting

Append Header in CSV file

Hi, I create a csv file and the output looks like below Arun,E001 Sathish,E003 Now i need to include the below header and the output should like below Name,Number Arun,E001 Sathish,E003 Please guide me. Thanks (4 Replies)
Discussion started by: Sekar1
4 Replies

8. Shell Programming and Scripting

Deleting rows from csv file

Hello, I am supposed to process about 100 csv files. But these files have some extra lines at the bottom of the file. these extra lines start with a header for each column and then some values below. These lines are actually a summary of the actual data and not supposed to be processed. These... (8 Replies)
Discussion started by: cobroraj
8 Replies

9. Shell Programming and Scripting

[HELP] - Delete rows on a CSV file

Hello to all members, I am very new in unix stuff (shell scripting), but a want to learn a lot. I am a ex windows user but now i am absolutely Linux super user... :D So i am tryng to made a function to do this: I have two csv files only with numbers, the first one a have: 1 2 3 4 5... (6 Replies)
Discussion started by: Sadarrab
6 Replies

10. Shell Programming and Scripting

How to append a Value to all the rows in a file

Hi, We have Multiple source files which has some data, I need a K shell script which will append number '1' as the last character to all the lines of the first file and then increments the value and appends '2' to all the lines to the next file and so on. For Example Incoming file 1 ... (2 Replies)
Discussion started by: dsshishya
2 Replies
Login or Register to Ask a Question