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
If you're going to use a "while read ... " construct, why not specify enough variables to cover what you need?
eg.
"insert" might be a function you create to do the actual sql insert. Specify an f8 variable so that if there are more columns than 7 you just put everything after the 7th column into f8 which you don't need.
This elimnates the need to echo $line | cut ...
Also use the special shell variable "IFS" and set that to "," before going into the while loop I've described. Do a man on your shell and search for "IFS" for more info on this.
You probably want to set a variable IFS_HOLD=$IFS before changing the IFS variable, so that you can restore it later in the script, should you need the default IFS behavior later on.
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)
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)
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)
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)
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)
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)
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)
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)
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)