01-28-2009
script to convert CSV to SQL
I am trying to write a script to convert csv files into SQL format.
What I am missing is:
1. handling of the first row and create it as a insert into format
2. better handling of any other row, and create a line with the data. *The while read line needs a better work.
I thought of using awk.
I will appreciate any help.
This is what I have so far (taken from readfile2.sh script)
PHP Code:
# Make sure we get file name as command line argument
# Else read it from standard input device
if [ "$1" == "" ]; then
echo "No File - Exit"
exit 1
else
FILE="$1"
# make sure file exist and readable
if [ ! -f $FILE ]; then
echo "$FILE : does not exists"
exit 1
elif [ ! -r $FILE ]; then
echo "$FILE: can not read"
exit 2
fi
fi
# field seprator, default is :, you can use blank space or
# other character, if you have more than one blak space in
# input line then use awk utility and not the cut :)
FS=","
while read line
do
# store field 1
F1=$(echo $line|cut -d$FS -f1)
# store field 2
F2=$(echo $line|cut -d$FS -f6)
# store field
F3=$(echo $line|cut -d$FS -f7)
echo "User \"$F1\" home directory is $F2 and login shell is $F3"
done < $FILE
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi Scripting gurus,
I need to convert following text snippet into csv. please help
Input
heading1 = data1
heading2 = data2
..
..
heading n = data n
heading 1 = data1
..
..
Output
data1,data2,....,data n (3 Replies)
Discussion started by: azs0309
3 Replies
2. Shell Programming and Scripting
Dear guys;
I have a binary file and I need to convert its data to csv format ...appreciating your help.
Best Regards (14 Replies)
Discussion started by: ahmad.diab
14 Replies
3. Shell Programming and Scripting
Hi
Written some script to convert csv to html but could not add table headers.Below are the errors iam getting
./csv2html | more
+ awk -v border=1 -v width=10 -v bgcolor=black -v fgcolor=white
BEGIN { printf("<table border=\"%d\" bordercolor=\"%s\" width=\"%d\"... (2 Replies)
Discussion started by: zeebala1981
2 Replies
4. Shell Programming and Scripting
I need to call and execute an SQL script within a KSH script and get the output/extracted data into a CSV file. Is there any way to get the out put in a CSV file other than spooling ?
I tried spooling. Problem is if there is any wrning/comment/Error they all will be spooled into the csv file. I... (4 Replies)
Discussion started by: Sriranga
4 Replies
5. Shell Programming and Scripting
hi
Can anybody help me with converting such structure into csv file for windows :
BAT_ID ID_num CVS_LINE A_SEG SKILL_TO A_CUSTOMER_TYPE
--------- ---------- --------------------------------- ---------- ------------------ -----------
14-MAY-11 777752 ... (4 Replies)
Discussion started by: kvok
4 Replies
6. Shell Programming and Scripting
Hi,
I have made a a script which creates a csv file as daily database report
However i want to covert that csv file to html because csv file does not have a good visibilty.
So it is possible to have such csv to html coversion script.
Your prompt help much appreciated. Thanks in advance (4 Replies)
Discussion started by: sv0081493
4 Replies
7. UNIX for Dummies Questions & Answers
I need to compare a R$Timestamp field sql within a Unix Shell Script.
In straight SQL the following code works fine:
Table Name: LL_UNIT_TRANSACTION UT
Field: R$Timestamp
Where TRUNC(UT.R$Timestamp) >= TRUNC(SYSDATE -7)
the following returns no data within the Unix Shell Script... (2 Replies)
Discussion started by: Dapconsult
2 Replies
8. Shell Programming and Scripting
Hi All,
I have a query with output below
select 'create synonym "'||TABLE_NAME||'" for '||Table_owner||'."'||table_name||'"'||chr(59) from user_synonyms;
==================
create synonym "RV_SBC_SIG" for WFCONTROLLER_TE."RV_SBC_SIG";
create synonym "AQM_TASK" for AWQM_TE."AQM_TASK";... (2 Replies)
Discussion started by: pvmanikandan
2 Replies
9. Shell Programming and Scripting
How to convert name.sql file into name.csv file.
Basically my input source file is .sql file, I need to verify data after the import of that exported sql file.
Thanks for any help. (3 Replies)
Discussion started by: wamqemail2
3 Replies
10. Shell Programming and Scripting
Hi Team,
i have some script which give output in TXT format , need script to convert TXT file into CSV.
Output.TXT
413. U-UU-LVDT-NOD-6002 macro_outcome_dist-8.0.0(v1_0_2) KK:1.2.494 (1234:333:aaa:2333:3:2:333:a)
414. U-UU-LVDT-NOD-6004 ... (10 Replies)
Discussion started by: Ganesh Mankar
10 Replies