Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2004

    Unanswered: bcp'ing to screen rather than file ?

    Is there a way for me to dump the output from bcp to the screen then piping it through something like sed, awk instead of out'ing it to a file? The reason is I want to do some formating of the output before writing it to file (there are several very large files/tables also note that the tables that I need to bcp change regularly....I'm not overly keen in attempting the use of format files) :

    bcp myDB.dbomyTable out myOutFile.csv -Umyuser -Pmypass -Smyserver -t\"\,\" -c
    Instead of out'ing to myOutFile.csv I would rather out to stdout and then pipe through sed:

    bcp myDB.dbomyTable out -Umyuser -Pmypass -Smyserver -t\"\,\" -c | sed 's/^/"/;s/$/"/'

    The sed simply adds a trailing and leading double quote.

    (or is there a easier way to do this...ultimately I want to columns wrapped in double quotes and comma separated)
    Last edited by bluwulf; 10-20-05 at 22:00.

  2. #2
    Join Date
    Jan 2003
    Geneva, Switzerland
    bcp out to a named pipe, and then cat from the named pipe through whatever filters you want to use.

    Look at the mknod man page on how to create the named pipe.


  3. #3
    Join Date
    May 2005
    South Africa
    Provided Answers: 1

    named pipe example

    $ mkfifo /tmp/bcpfifo
    $ cat /tmp/bcpfifo | gzip -9c >/tmp/bcpdata.gz & 
    [1]     27836
    $ bcp master..sysdatabases out /tmp/bcpfifo -Uuid -Ppasswd -Ssrvname -c
    Starting copy...
    9 rows copied.
    Clock Time (ms.): total = 1  Avg = 0 (9000.00 rows per sec.)
    [1] +  Done                    cat /tmp/bcpfifo | gzip -9c >/tmp/bcpdata.gz &

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts