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.
Please use [code][/code] tags so we can ascertain if you are entering data correctly.
Also you say this for a server ... would it happen to be Solaris?I have had issues from other users on this platform
as awk seems to be quite dated. Maybe provide:
Code:
awk --version
Maybe you could alter the RS portion from mine to the following:
I might be missing the point, but it seems like a one-liner won't do the trick since INSERT only takes one row at a time. I would therefore do something like this:
Code:
#!/bin/bash
filename="$1"
cat "$filename" | tr '\n\r' ' ' | sed 's/, /,/g' | sed -r 's/ [[:digit:]]{8} /&\n/g' | while read line; do
read server fields date < <( echo "$line" )
echo "I am inserting [server=$server] [fields=$fields] [date=$date] into the table"
done
In the code above, you'd obviously create an INSERT statement from $server, $fields, and $date. I'm not sure how it's helpful to split the comma-separated values, however, since "SERVER001" and "SERVER002" don't have the same number of values.
Kevin Barry
I might be missing the point, but it seems like a one-liner won't do the trick since INSERT only takes one row at a time. I would therefore do something like this:
Code:
#!/bin/bash
filename="$1"
cat "$filename" | tr '\n\r' ' ' | sed 's/, /,/g' | sed -r 's/ [[:digit:]]{8} /&\n/g' | while read line; do
read server fields date < <( echo "$line" )
echo "I am inserting [server=$server] [fields=$fields] [date=$date] into the table"
done
In the code above, you'd obviously create an INSERT statement from $server, $fields, and $date. I'm not sure how it's helpful to split the comma-separated values, however, since "SERVER001" and "SERVER002" don't have the same number of values.
Kevin Barry
Exactly ... which is (in less words) what I said in #7.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.