[thelist] Re: bash, read from several files

Walter Hemingway walt at medianetwork.ws
Sun Apr 18 12:21:38 CDT 2004


 Please HELP!!!

I need an ecommerce solution. I am working on a site and my client needs a
calculator that will give state to state shipping rates by Zip Code.
Possibly configured to work with Paypal. I have looked at UPS and I don't
think that they have what I need ( I could be wrong, but I won't get an
answer from them until Monday). Any shopping cart solutions or apps would be
appreciated. The actual site is complete except for the shipping calculator
for the shopping cart. PLEASE HELP!!!


Thank You,
Walter S. Hemingway
(803)419-7539 hm
(803)748-8594 off

-----Original Message-----
From: thelist-bounces at lists.evolt.org
[mailto:thelist-bounces at lists.evolt.org] On Behalf Of Eduardo Bacchi Kienetz
Sent: Saturday, April 17, 2004 6:31 PM
To: thelist at lists.evolt.org
Subject: [thelist] Re: bash, read from several files

In time:
For that one line to work you should run first: export IFS="/" (if your
names do not contain /), or simply this one line:

export IFS="/" ; cat name.txt emails.txt etc.txt bla.sql | xargs -n1 -i
pgsql -d nobody -c "INSERT INTO contact(name) VALUES('{}')" ; export IFS=" "

:)

---------------------------------
Hi Magnus,

Try this (read the whole message first):

#!/bin/sh
export IFS="/"
for NAME in "cat name.txt emails.txt etc.txt bla.sql"
do
    psql -d nobody nobody -c "INSERT INTO contact(name) VALUES('$NAME');"
done
export IFS=" "

NAME will have every name while looping. You should note that if the name
contains space you'd have trouble because it would save "Eduardo Kienetz" on
two records, "Eduardo" and another record for "Kienetz".
That's why I change the FS variable, which stands for the separator (which
previously was SPACE).

A simpler way of accomplishing that would be this command:
cat name.txt emails.txt etc.txt bla.sql | xargs -n1 -i pgsql -d nobody -c
"INSERT INTO contact(name) VALUES('{}')"

xargs does the magic. It will run pgsql for each line of your files
(name.txt emails.txt etc.txt bla.sql, etc).
Each line value is represented by the {}

Regards,

Eduardo Bacchi Kienetz
Senior Support Analyst on *nix Systems

--------------------------

>Date: Sat, 17 Apr 2004 03:57:13 +0200 (CEST)
>From: "=?iso-8859-1?Q?Magnus_=D8stergaard?=" <magnus at slackware.adsl.dk>
>To: <thelist at lists.evolt.org>
>Subject: [thelist] bash, read from several file
>Message-ID: 
><17441.212.242.116.232.1082167033.squirrel at webmail.firstimpact.dk>
>Content-Type: text/plain; charset=iso-8859-1
>MIME-Version: 1.0
>Content-Transfer-Encoding: 8bit
>Precedence: list
>Reply-To: "thelist at lists.evolt.org" <thelist at lists.evolt.org>
>Message: 6
>
>Hi,
>
>I am trying to populate a postgresql db with values from several files.
>In each file, each line correspont to the same line number in the other 
>files.
>The problem is how do I make my loop?
>
>This is what I've got so far:
>
>#!/bin/sh
>while read name;
> do psql -d nobody nobody -c "INSERT INTO contact(name) 
>VALUES('$name');" ; done< ./name.txt
>
>But this only reads one file.
>
>How can I read from two files (or more) at one time. Say name.txt and 
>email.txt and then do.
>
>"INSERT INTO contact(name,email) VALUES('$name','$email');"

--
* * Please support the community that supports you.  * *
http://evolt.org/help_support_evolt/

For unsubscribe and other options, including the Tip Harvester and archives
of thelist go to: http://lists.evolt.org Workers of the Web, evolt ! 



More information about the thelist mailing list