Script for parsing a text file and inserting into DB
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Now i have to parse data3 and data4 of every line and send as variable to a sql select command which will connect to a DB and find out two information and lastly create a new file like following
data1, data2, data3, data4, data5, data6
...
..
.
I have done the parsing portion like this
#!/bin/bash
# Set the field seperator to a newline
IFS="
"
file=$1
cat $file | while read fileline
do
col8=$(echo $fileline | cut -d',' -f8)
col9=$(echo $fileline | cut -d',' -f9)
echo $col8 $col9
done
Now i need to do the rest of the part ..can any one help me.
So are you saying you do not know how to write the sql query?
Also i am not sure how the code (which you should place in [code][/code] tags to make readable)
is doing what you want?? You say you want the third and fourth columns but then use cut to get fields eight and nine??
Also, setting IFS and using cat are not required at all as the while loop can already handle both:
Sorry Bro it should be -f3 and -f4. I was just working with another script and i copied it from there. I know the query but i dont know how to integrate the query with scripting and how to generate another csv file with some portion from first csv file and another portion that query. And I am not setting IFS also.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.