Thread: Copy entire file as one field

Copy entire file as one field

From
"Warren Massengill"
Date:
How can I copy several hundred small text files into a database, each file
going into a field called 'message' and becomming one record (with or
without other fields) using psql?

PostgreSQL 7.2.2
RedHat 8.0

Thanks,
Warren

_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail


DB dump problems

From
"Gallamine"
Date:
Hello, newbie here (ha, imagine that). Anyways, I worked this summer
rewriting my website to use PHP and PostreSQL. I was doing that away from my
home. I didn't backup the DB and recently I've been wanting to start again
using my Linux (RH 8) box here at home. So, I've been playing around with
the pg_dump command trying to get it to work right. I make heavy use of the
OIDs in my DB so I know I have to use the -o switch. However, when I take
the dump from work and move it to my home and try to recreate my database (I
did pg_dump -C -o > outputfile.txt) I get the following error:

You are now connected to database gorobotics2.
CREATE
": can't parse "ne 1, pg_atoi: error in "0
lost synchronization with server, resetting connection

There isn't anything in my dump that says "ne 1, pg_atoi ..." Also I try
recreating the DB on the computer I got the dump from and it works fine.

Does anyone know why I can't do this?
-William



Re: Copy entire file as one field

From
Ron Johnson
Date:
On Wed, 2002-11-27 at 18:40, Warren Massengill wrote:
> How can I copy several hundred small text files into a database, each file
> going into a field called 'message' and becomming one record (with or
> without other fields) using psql?

Don't know about psql, but you could use python or perl (heck, even C!)
to script it pretty easily.

--
+------------------------------------------------------------+
| Ron Johnson, Jr.     mailto:ron.l.johnson@cox.net          |
| Jefferson, LA  USA   http://members.cox.net/ron.l.johnson  |
|                                                            |
| "they love our milk and honey, but preach about another    |
|  way of living"                                            |
|    Merle Haggard, "The Fighting Side Of Me"                |
+------------------------------------------------------------+


Re: DB dump problems

From
Ron Johnson
Date:
On Wed, 2002-11-27 at 19:46, Gallamine wrote:
> Hello, newbie here (ha, imagine that). Anyways, I worked this summer
> rewriting my website to use PHP and PostreSQL. I was doing that away from my
> home. I didn't backup the DB and recently I've been wanting to start again
> using my Linux (RH 8) box here at home. So, I've been playing around with
> the pg_dump command trying to get it to work right. I make heavy use of the
> OIDs in my DB so I know I have to use the -o switch. However, when I take
> the dump from work and move it to my home and try to recreate my database (I
> did pg_dump -C -o > outputfile.txt) I get the following error:
>
> You are now connected to database gorobotics2.
> CREATE
> ": can't parse "ne 1, pg_atoi: error in "0
> lost synchronization with server, resetting connection
>
> There isn't anything in my dump that says "ne 1, pg_atoi ..." Also I try
> recreating the DB on the computer I got the dump from and it works fine.
>
> Does anyone know why I can't do this?

Can we presume that it's the same PG version on both boxen, and that the
same options were used when generating the PG binaries and at
installation on each box?

--
+------------------------------------------------------------+
| Ron Johnson, Jr.     mailto:ron.l.johnson@cox.net          |
| Jefferson, LA  USA   http://members.cox.net/ron.l.johnson  |
|                                                            |
| "they love our milk and honey, but preach about another    |
|  way of living"                                            |
|    Merle Haggard, "The Fighting Side Of Me"                |
+------------------------------------------------------------+


Re: Copy entire file as one field

From
"Warren Massengill"
Date:
I'm not really a Perl programmer. I can see how to write a loop and open a
specific file but don't know how to tell Perl to copy the file into a db or
how to work through a directory of files of various names. But I'll work on
it.

Thanks,
Warren


>From: Ron Johnson <ron.l.johnson@cox.net>
>To: PgSQL Novice ML <pgsql-novice@postgresql.org>
>Subject: Re: [NOVICE] Copy entire file as one field
>Date: 27 Nov 2002 20:26:45 -0600
>
>On Wed, 2002-11-27 at 18:40, Warren Massengill wrote:
> > How can I copy several hundred small text files into a database, each
>file
> > going into a field called 'message' and becomming one record (with or
> > without other fields) using psql?
>
>Don't know about psql, but you could use python or perl (heck, even C!)
>to script it pretty easily.
>
>--
>+------------------------------------------------------------+
>| Ron Johnson, Jr.     mailto:ron.l.johnson@cox.net          |
>| Jefferson, LA  USA   http://members.cox.net/ron.l.johnson  |
>|                                                            |
>| "they love our milk and honey, but preach about another    |
>|  way of living"                                            |
>|    Merle Haggard, "The Fighting Side Of Me"                |
>+------------------------------------------------------------+
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 4: Don't 'kill -9' the postmaster


_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
http://join.msn.com/?page=features/virus


Re: DB dump problems

From
Tom Lane
Date:
"Gallamine" <iam@gallamine.com> writes:
> You are now connected to database gorobotics2.
> CREATE
> ": can't parse "ne 1, pg_atoi: error in "0
> lost synchronization with server, resetting connection

> There isn't anything in my dump that says "ne 1, pg_atoi ..."

This looks a lot like a newline problem.  COPY only likes Unix-style
newlines (\n, a/k/a LF).  You've got DOS-style newlines (\r\n, a/k/a
CR/LF) or possibly Mac-style newlines (\r, a/k/a CR) in your data file.
This can be blamed on whatever method you used to transfer the dump
file from old machine to new.  Try again, and try transferring the dump
as binary data not text.

            regards, tom lane

Re: Copy entire file as one field

From
Oliver Elphick
Date:
On Thu, 2002-11-28 at 00:40, Warren Massengill wrote:
> How can I copy several hundred small text files into a database, each file
> going into a field called 'message' and becomming one record (with or
> without other fields) using psql?

A bit of shell scripting:

for f in `ls small_file*`
do
    psql -d mydatabase -c "INSERT INTO mytable (message)
                 VALUES ('`cat $f`')"
done


--
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight, UK                             http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "The earth is the LORD'S, and the fullness thereof; the
      world, and they that dwell therein."       Psalms 24:1

Attachment

Re: Copy entire file as one field

From
"Warren Massengill"
Date:
My database is pg, the table is mail.
The small text files are in /home/kelly/message/.
The bash shell script is merge.

Somehow I failed to translate your instructions...

-----------------------------------------------------
#!/bin/bash

for f in `ls /home/kelly/message*`
do
        psql -d pg -c "INSERT INTO mail (message)
                                 VALUES ('`cat $f`')"
done

----------------------------------------------------
[kelly@localhost message]$ merge
merge: not enough arguments
merge: usage: merge [-AeEpqxX3] [-L lab [-L lab [-L lab]]] file1 file2 file3
merge aborted

----------------------------------------------------
Thanks,
Warren

>From: Oliver Elphick <olly@lfix.co.uk>
>To: Warren Massengill <warrenmassengill@hotmail.com>
>CC: pgsql-novice@postgresql.org
>Subject: Re: [NOVICE] Copy entire file as one field
>Date: 28 Nov 2002 07:43:12 +0000
>
>On Thu, 2002-11-28 at 00:40, Warren Massengill wrote:
> > How can I copy several hundred small text files into a database, each
>file
> > going into a field called 'message' and becomming one record (with or
> > without other fields) using psql?
>
>A bit of shell scripting:
>
>for f in `ls small_file*`
>do
>    psql -d mydatabase -c "INSERT INTO mytable (message)
>                 VALUES ('`cat $f`')"
>done
>
>
>--
>Oliver Elphick                                Oliver.Elphick@lfix.co.uk
>Isle of Wight, UK                             http://www.lfix.co.uk/oliver
>GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
>                  ========================================
>      "The earth is the LORD'S, and the fullness thereof; the
>       world, and they that dwell therein."       Psalms 24:1
><< signature.asc >>


_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8.
http://join.msn.com/?page=features/junkmail


Re: Copy entire file as one field

From
"Warren Massengill"
Date:
RedHat 8 has Python tutorials and docs. All written in Python. Apparently
you have to buy a book to read the RedHat docs. :-(

Actually, it's not quite that bad. I haven't given up on Python but just
haven't had time to work it out yet.

j\Thanks,
Warren


>From: Ron Johnson <ron.l.johnson@cox.net>
>To: Warren Massengill <warrenmassengill@hotmail.com>
>Subject: Re: [NOVICE] Copy entire file as one field
>Date: 28 Nov 2002 06:01:07 -0600
>
>On Wed, 2002-11-27 at 20:56, Warren Massengill wrote:
> > I'm not really a Perl programmer. I can see how to write a loop and open
>a
> > specific file but don't know how to tell Perl to copy the file into a db
>or
> > how to work through a directory of files of various names. But I'll work
>on
> > it.
> >
> > Thanks,
> > Warren
> >
>
>I don't know perl either!  Attached, though, something like what I'd
>try in python, if all of the small text files are all, and by
>themselves, in a single directory, and you are in that directory.
>The only gotcha might be that the INSERT statement might not like
>all those \n characters...
>
> >
> > >From: Ron Johnson <ron.l.johnson@cox.net>
> > >To: PgSQL Novice ML <pgsql-novice@postgresql.org>
> > >Subject: Re: [NOVICE] Copy entire file as one field
> > >Date: 27 Nov 2002 20:26:45 -0600
> > >
> > >On Wed, 2002-11-27 at 18:40, Warren Massengill wrote:
> > > > How can I copy several hundred small text files into a database,
>each
> > >file
> > > > going into a field called 'message' and becomming one record (with
>or
> > > > without other fields) using psql?
> > >
> > >Don't know about psql, but you could use python or perl (heck, even C!)
> > >to script it pretty easily.
>
>--
>+------------------------------------------------------------+
>| Ron Johnson, Jr.     mailto:ron.l.johnson@cox.net          |
>| Jefferson, LA  USA   http://members.cox.net/ron.l.johnson  |
>|                                                            |
>| "they love our milk and honey, but preach about another    |
>|  way of living"                                            |
>|    Merle Haggard, "The Fighting Side Of Me"                |
>+------------------------------------------------------------+
><< pgload.warren.py >>


_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail


Re: Copy entire file as one field

From
Oliver Elphick
Date:
On Tue, 2002-12-03 at 19:48, Warren Massengill wrote:
> My database is pg, the table is mail.
> The small text files are in /home/kelly/message/.
> The bash shell script is merge.
>
> Somehow I failed to translate your instructions...
>
> -----------------------------------------------------
> #!/bin/bash
>
> for f in `ls /home/kelly/message*`
                               ^^^^^^
                           message/*

> do
>         psql -d pg -c "INSERT INTO mail (message)
>                                  VALUES ('`cat $f`')"
> done

Your files are in that directory, so the wild card must be too.
--
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight, UK                             http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "What shall we then say to these things? If God be for
      us, who can be against us?"              Romans 8:31


Re: Copy entire file as one field

From
"Devinder K Rajput"
Date:
Warren,

merge is an actual linux utility used to merge files.  When you ran the
command it found the system command before it could get to your script.  To
run your program, cd to the your program is  stored.  Then type in
   ./merge

This will execute the program in your current directory.  This should do
the trick,

Devinder




                    
                      "Warren Massengill"
                    
                      <warrenmassengill@hotm        To:       olly@lfix.co.uk
                    
                      ail.com>                      cc:       pgsql-novice@postgresql.org
                    
                      Sent by:                      Subject:  Re: [NOVICE] Copy entire file as one field
                    
                      pgsql-novice-owner@pos
                    
                      tgresql.org
                    

                    

                    
                      12/03/2002 01:48 PM
                    

                    

                    




My database is pg, the table is mail.
The small text files are in /home/kelly/message/.
The bash shell script is merge.

Somehow I failed to translate your instructions...

-----------------------------------------------------
#!/bin/bash

for f in `ls /home/kelly/message*`
do
        psql -d pg -c "INSERT INTO mail (message)
                                 VALUES ('`cat $f`')"
done

----------------------------------------------------
[kelly@localhost message]$ merge
merge: not enough arguments
merge: usage: merge [-AeEpqxX3] [-L lab [-L lab [-L lab]]] file1 file2
file3
merge aborted

----------------------------------------------------
Thanks,
Warren

>From: Oliver Elphick <olly@lfix.co.uk>
>To: Warren Massengill <warrenmassengill@hotmail.com>
>CC: pgsql-novice@postgresql.org
>Subject: Re: [NOVICE] Copy entire file as one field
>Date: 28 Nov 2002 07:43:12 +0000
>
>On Thu, 2002-11-28 at 00:40, Warren Massengill wrote:
> > How can I copy several hundred small text files into a database, each
>file
> > going into a field called 'message' and becomming one record (with or
> > without other fields) using psql?
>
>A bit of shell scripting:
>
>for f in `ls small_file*`
>do
>     psql -d mydatabase -c "INSERT INTO mytable (message)
>                        VALUES ('`cat $f`')"
>done
>
>
>--
>Oliver Elphick                                Oliver.Elphick@lfix.co.uk
>Isle of Wight, UK                             http://www.lfix.co.uk/oliver
>GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
>                  ========================================
>      "The earth is the LORD'S, and the fullness thereof; the
>       world, and they that dwell therein."       Psalms 24:1
><< signature.asc >>


_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8.
http://join.msn.com/?page=features/junkmail


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html







Re: Copy entire file as one field

From
"Warren Massengill"
Date:
The revised version has the same result. If I change the name of the script
(another poster suggested avoiding the reserved word 'merge') there is a
different error message.

Thanks,
Warren

------------------------------------
#!/bin/bash

for f in `ls /home/kelly/message/*`
do
        psql -d pg -c "INSERT INTO mail (message)
                                 VALUES ('`cat $f`')"
done

-------------------------------------
[kelly@localhost pg]$ merge
merge: not enough arguments
merge: usage: merge [-AeEpqxX3] [-L lab [-L lab [-L lab]]] file1 file2 file3
merge aborted
--------------------------------------
[kelly@localhost pg]$ merge4
bash: merge4: command not found
--------------------------------------
>
>On Tue, 2002-12-03 at 19:48, Warren Massengill wrote:
> > My database is pg, the table is mail.
> > The small text files are in /home/kelly/message/.
> > The bash shell script is merge.
> >
> > Somehow I failed to translate your instructions...
> >
> > -----------------------------------------------------
> > #!/bin/bash
> >
> > for f in `ls /home/kelly/message*`
>                                ^^^^^^
>                            message/*
>
> > do
> >         psql -d pg -c "INSERT INTO mail (message)
> >                                  VALUES ('`cat $f`')"
> > done
>
>Your files are in that directory, so the wild card must be too.
>--
>Oliver Elphick                                Oliver.Elphick@lfix.co.uk


_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail


Re: Copy entire file as one field

From
"Devinder K Rajput"
Date:
What error msg do you get after you change the name of the script?

Devinder



                    
                      "Warren Massengill"
                    
                      <warrenmassengill@hotm        To:       olly@lfix.co.uk
                    
                      ail.com>                      cc:       pgsql-novice@postgresql.org
                    
                      Sent by:                      Subject:  Re: [NOVICE] Copy entire file as one field
                    
                      pgsql-novice-owner@pos
                    
                      tgresql.org
                    

                    

                    
                      12/04/2002 12:16 PM
                    

                    

                    





The revised version has the same result. If I change the name of the script
(another poster suggested avoiding the reserved word 'merge') there is a
different error message.

Thanks,
Warren

------------------------------------
#!/bin/bash

for f in `ls /home/kelly/message/*`
do
        psql -d pg -c "INSERT INTO mail (message)
                                 VALUES ('`cat $f`')"
done

-------------------------------------
[kelly@localhost pg]$ merge
merge: not enough arguments
merge: usage: merge [-AeEpqxX3] [-L lab [-L lab [-L lab]]] file1 file2
file3
merge aborted
--------------------------------------
[kelly@localhost pg]$ merge4
bash: merge4: command not found
--------------------------------------
>
>On Tue, 2002-12-03 at 19:48, Warren Massengill wrote:
> > My database is pg, the table is mail.
> > The small text files are in /home/kelly/message/.
> > The bash shell script is merge.
> >
> > Somehow I failed to translate your instructions...
> >
> > -----------------------------------------------------
> > #!/bin/bash
> >
> > for f in `ls /home/kelly/message*`
>                                ^^^^^^
>                            message/*
>
> > do
> >         psql -d pg -c "INSERT INTO mail (message)
> >                                  VALUES ('`cat $f`')"
> > done
>
>Your files are in that directory, so the wild card must be too.
>--
>Oliver Elphick                                Oliver.Elphick@lfix.co.uk


_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org







Re: Copy entire file as one field

From
Ron Johnson
Date:
On Wed, 2002-12-04 at 12:16, Warren Massengill wrote:
> The revised version has the same result. If I change the name of the script
> (another poster suggested avoiding the reserved word 'merge') there is a
> different error message.


You *must* run your script this way:
$ ./merge4

And you did make sure that the script is executable, right?

> ------------------------------------
> #!/bin/bash
>
> for f in `ls /home/kelly/message/*`
> do
>         psql -d pg -c "INSERT INTO mail (message)
>                                  VALUES ('`cat $f`')"
> done
>
> -------------------------------------
> [kelly@localhost pg]$ merge
> merge: not enough arguments
> merge: usage: merge [-AeEpqxX3] [-L lab [-L lab [-L lab]]] file1 file2 file3
> merge aborted
> --------------------------------------
> [kelly@localhost pg]$ merge4
> bash: merge4: command not found
> --------------------------------------
> >
> >On Tue, 2002-12-03 at 19:48, Warren Massengill wrote:
> > > My database is pg, the table is mail.
> > > The small text files are in /home/kelly/message/.
> > > The bash shell script is merge.
> > >
> > > Somehow I failed to translate your instructions...
> > >
> > > -----------------------------------------------------
> > > #!/bin/bash
> > >
> > > for f in `ls /home/kelly/message*`
> >                                ^^^^^^
> >                            message/*
> >
> > > do
> > >         psql -d pg -c "INSERT INTO mail (message)
> > >                                  VALUES ('`cat $f`')"
> > > done
> >
> >Your files are in that directory, so the wild card must be too.
> >--

--
+------------------------------------------------------------+
| Ron Johnson, Jr.     mailto:ron.l.johnson@cox.net          |
| Jefferson, LA  USA   http://members.cox.net/ron.l.johnson  |
|                                                            |
| "they love our milk and honey, but preach about another    |
|  way of living"                                            |
|    Merle Haggard, "The Fighting Side Of Me"                |
+------------------------------------------------------------+


Re: Copy entire file as one field

From
"Devinder K Rajput"
Date:
I think this should have gone to the entire list.

Devinder




               
                      "David C. Oshel"
               
                      <dcoshel@inav.net        To:       "Devinder K Rajput" <Devinder.Rajput@ipaper.com>
               
                      >                        cc:
               
                                               Subject:  Re: [NOVICE] Copy entire file as one field
               
                      12/04/2002 12:53
               
                      PM
               

               

               




does echo '`cat $f`' work?

On Wednesday, December 4, 2002, at 12:30  PM, Devinder K Rajput wrote:

> ('`cat $f`')"
--
David C. Oshel               mailto:dcoshel@inav.net
Cedar Rapids, Iowa       http://soli.inav.net/~dcoshel
``I think most pleasantly in metaphors, and smoking brings metaphors to
mind." - Augustus Srb, in Alexei Panshin's  _Star Well_








Re: Copy entire file as one field

From
"Warren Massengill"
Date:
>From: "Devinder K Rajput" <Devinder.Rajput@ipaper.com>
>
>What error msg do you get after you change the name of the script?
>
>Devinder

Sorry, I should have said that the revised script (merge4) error message was
shown below...
--------------------------------------
[kelly@localhost pg]$ merge4
bash: merge4: command not found
--------------------------------------
Thanks,
Warren
>
>The revised version has the same result. If I change the name of the script
>(another poster suggested avoiding the reserved word 'merge') there is a
>different error message.
>
>Thanks,
>Warren
>
>------------------------------------
>#!/bin/bash
>
>for f in `ls /home/kelly/message/*`
>do
>         psql -d pg -c "INSERT INTO mail (message)
>                                  VALUES ('`cat $f`')"
>done
>
>-------------------------------------
>[kelly@localhost pg]$ merge
>merge: not enough arguments
>merge: usage: merge [-AeEpqxX3] [-L lab [-L lab [-L lab]]] file1 file2
>file3
>merge aborted
>--------------------------------------
>[kelly@localhost pg]$ merge4
>bash: merge4: command not found
>--------------------------------------
> >
> >On Tue, 2002-12-03 at 19:48, Warren Massengill wrote:
> > > My database is pg, the table is mail.
> > > The small text files are in /home/kelly/message/.
> > > The bash shell script is merge.
> > > -----------------------------------------------------
> > > #!/bin/bash
> > >
> > > for f in `ls /home/kelly/message*`
> >                                ^^^^^^
> >                            message/*
> >
> > > do
> > >         psql -d pg -c "INSERT INTO mail (message)
> > >                                  VALUES ('`cat $f`')"
> > > done
> >
> >Your files are in that directory, so the wild card must be too.
> >--
> >Oliver Elphick                                Oliver.Elphick@lfix.co.uk

_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8.
http://join.msn.com/?page=features/junkmail


Re: Copy entire file as one field

From
"Devinder K Rajput"
Date:
I just tested this right off the command line and it works fine:

drajput$ for f in `ls ~drajput/tmp/mail/*`; do psql -d counterpointtest -c
"INSERT INTO mail(message) VALUES('`cat $f`')";done
^^^^^^^^^^^^^
db name

regards

Devinder Rajput
Stores Division Corporate Offices
Chicago, IL
(773) 442-6474



                    
                      "Ron Johnson"
                    
                      <ron.l.johnson@cox.net        To:       "PgSQL Novice ML" <pgsql-novice@postgresql.org>
                    
                      >                             cc:
                    
                      Sent by:                      Subject:  Re: [NOVICE] Copy entire file as one field
                    
                      pgsql-novice-owner@pos
                    
                      tgresql.org
                    

                    

                    
                      12/04/2002 12:40 PM
                    

                    

                    




On Wed, 2002-12-04 at 12:16, Warren Massengill wrote:
> The revised version has the same result. If I change the name of the
script
> (another poster suggested avoiding the reserved word 'merge') there is a
> different error message.


You *must* run your script this way:
$ ./merge4

And you did make sure that the script is executable, right?

> ------------------------------------
> #!/bin/bash
>
> for f in `ls /home/kelly/message/*`
> do
>         psql -d pg -c "INSERT INTO mail (message)
>                                  VALUES ('`cat $f`')"
> done
>
> -------------------------------------
> [kelly@localhost pg]$ merge
> merge: not enough arguments
> merge: usage: merge [-AeEpqxX3] [-L lab [-L lab [-L lab]]] file1 file2
file3
> merge aborted
> --------------------------------------
> [kelly@localhost pg]$ merge4
> bash: merge4: command not found
> --------------------------------------
> >
> >On Tue, 2002-12-03 at 19:48, Warren Massengill wrote:
> > > My database is pg, the table is mail.
> > > The small text files are in /home/kelly/message/.
> > > The bash shell script is merge.
> > >
> > > Somehow I failed to translate your instructions...
> > >
> > > -----------------------------------------------------
> > > #!/bin/bash
> > >
> > > for f in `ls /home/kelly/message*`
> >                                ^^^^^^
> >                            message/*
> >
> > > do
> > >         psql -d pg -c "INSERT INTO mail (message)
> > >                                  VALUES ('`cat $f`')"
> > > done
> >
> >Your files are in that directory, so the wild card must be too.
> >--

--
+------------------------------------------------------------+
| Ron Johnson, Jr.     mailto:ron.l.johnson@cox.net          |
| Jefferson, LA  USA   http://members.cox.net/ron.l.johnson  |
|                                                            |
| "they love our milk and honey, but preach about another    |
|  way of living"                                            |
|    Merle Haggard, "The Fighting Side Of Me"                |
+------------------------------------------------------------+


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)







Re: Copy entire file as one field

From
"Warren Massengill"
Date:
I'm still missing something.....

Two identical files: merge and merge4; both executable by the world.
------------------------------------
$ ./merge or $ ./merge4
cannot find the file
------------------------------------
$ merge
apparently locates the file -- but cannot run it
------------------------------------
-rw-------    1 kelly    kelly        3062 Dec  3 11:57 logfile
-rwxrwxrwx    1 kelly    kelly         135 Dec  3 13:24 merge
-rwxrwxrwx    1 kelly    kelly         135 Dec  3 10:54 merge4
drwx------    2 kelly    kelly        4096 Dec  2 04:31 pg_clog
-rw-------    1 kelly    kelly       10168 Dec  2 04:31 pg_hba.conf
-rw-------    1 kelly    kelly        1250 Dec  2 04:31 pg_ident.conf
-rw-------    1 kelly    kelly           4 Dec  2 04:31 PG_VERSION
drwx------    2 kelly    kelly        4096 Dec  2 04:31 pg_xlog
-rw-------    1 kelly    kelly        3848 Dec  2 04:31 postgresql.conf
-rw-------    1 kelly    kelly          20 Dec  3 10:51 postmaster.opts
--------------------------------------
[kelly@localhost pg]$ ./merge
: bad interpreter: No such file or directory
[kelly@localhost pg]$ ./merge4
: bad interpreter: No such file or directory
--------------------------------------
[kelly@localhost pg]$ merge
merge: not enough arguments
merge: usage: merge [-AeEpqxX3] [-L lab [-L lab [-L lab]]] file1 file2 file3
merge aborted
[kelly@localhost pg]$
--------------------------------------

Thanks,
Warren

>
>You *must* run your script this way:
>$ ./merge4
>
>And you did make sure that the script is executable, right?
>
> > ------------------------------------
> > #!/bin/bash
> >
> > for f in `ls /home/kelly/message/*`
> > do
> >         psql -d pg -c "INSERT INTO mail (message)
> >                                  VALUES ('`cat $f`')"
> > done
> >
> > -------------------------------------
> > [kelly@localhost pg]$ merge
> > merge: not enough arguments
> > merge: usage: merge [-AeEpqxX3] [-L lab [-L lab [-L lab]]] file1 file2
>file3
> > merge aborted
> > --------------------------------------
> > [kelly@localhost pg]$ merge4
> > bash: merge4: command not found
> > --------------------------------------
> > >
> > >On Tue, 2002-12-03 at 19:48, Warren Massengill wrote:
> > > > My database is pg, the table is mail.
> > > > The small text files are in /home/kelly/message/.
> > > > The bash shell script is merge.

_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail


Re: Copy entire file as one field

From
"Devinder K Rajput"
Date:
from the error messages it seems that it can not the bash shell.  One thing
to try is
$ which bash

and see if returns with the location or  just try running the following one
liner  from the command line:

for f in `ls /home/kelly/message/*`;do psql -d pg -c "INSERT INTO mail
(message) VALUES ('`cat $f`')"; done

Devinder Rajput
Stores Division Corporate Offices
Chicago, IL
(773) 442-6474



                    
                      "Warren Massengill"
                    
                      <warrenmassengill@hotm        To:       ron.l.johnson@cox.net
                    
                      ail.com>                      cc:       pgsql-novice@postgresql.org
                    
                      Sent by:                      Subject:  Re: [NOVICE] Copy entire file as one field
                    
                      pgsql-novice-owner@pos
                    
                      tgresql.org
                    

                    

                    
                      12/04/2002 02:10 PM
                    

                    

                    





I'm still missing something.....

Two identical files: merge and merge4; both executable by the world.
------------------------------------
$ ./merge or $ ./merge4
cannot find the file
------------------------------------
$ merge
apparently locates the file -- but cannot run it
------------------------------------
-rw-------    1 kelly    kelly        3062 Dec  3 11:57 logfile
-rwxrwxrwx    1 kelly    kelly         135 Dec  3 13:24 merge
-rwxrwxrwx    1 kelly    kelly         135 Dec  3 10:54 merge4
drwx------    2 kelly    kelly        4096 Dec  2 04:31 pg_clog
-rw-------    1 kelly    kelly       10168 Dec  2 04:31 pg_hba.conf
-rw-------    1 kelly    kelly        1250 Dec  2 04:31 pg_ident.conf
-rw-------    1 kelly    kelly           4 Dec  2 04:31 PG_VERSION
drwx------    2 kelly    kelly        4096 Dec  2 04:31 pg_xlog
-rw-------    1 kelly    kelly        3848 Dec  2 04:31 postgresql.conf
-rw-------    1 kelly    kelly          20 Dec  3 10:51 postmaster.opts
--------------------------------------
[kelly@localhost pg]$ ./merge
: bad interpreter: No such file or directory
[kelly@localhost pg]$ ./merge4
: bad interpreter: No such file or directory
--------------------------------------
[kelly@localhost pg]$ merge
merge: not enough arguments
merge: usage: merge [-AeEpqxX3] [-L lab [-L lab [-L lab]]] file1 file2
file3
merge aborted
[kelly@localhost pg]$
--------------------------------------

Thanks,
Warren

>
>You *must* run your script this way:
>$ ./merge4
>
>And you did make sure that the script is executable, right?
>
> > ------------------------------------
> > #!/bin/bash
> >
> > for f in `ls /home/kelly/message/*`
> > do
> >         psql -d pg -c "INSERT INTO mail (message)
> >                                  VALUES ('`cat $f`')"
> > done
> >
> > -------------------------------------
> > [kelly@localhost pg]$ merge
> > merge: not enough arguments
> > merge: usage: merge [-AeEpqxX3] [-L lab [-L lab [-L lab]]] file1 file2
>file3
> > merge aborted
> > --------------------------------------
> > [kelly@localhost pg]$ merge4
> > bash: merge4: command not found
> > --------------------------------------
> > >
> > >On Tue, 2002-12-03 at 19:48, Warren Massengill wrote:
> > > > My database is pg, the table is mail.
> > > > The small text files are in /home/kelly/message/.
> > > > The bash shell script is merge.

_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster







Re: Copy entire file as one field

From
"Warren Massengill"
Date:






>From: "Devinder K Rajput" <Devinder.Rajput@ipaper.com>
>Date: Wed, 4 Dec 2002 14:30:18 -0600
>
>
>from the error messages it seems that it can not the bash shell.  One thing
>to try is
>$ which bash
>
>and see if returns with the location or  just try running the following one
>liner  from the command line:
>
>for f in `ls /home/kelly/message/*`;do psql -d pg -c "INSERT INTO mail
>(message) VALUES ('`cat $f`')"; done

Ahhhh, it works! I'll have to find out what's wrong with my shell scripting
but using this command line works for now.

Thanks to all.
Warren
>
>Devinder Rajput
>Stores Division Corporate Offices
>Chicago, IL
>(773) 442-6474

_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
http://join.msn.com/?page=features/virus