From: | Richard Huxton <dev(at)archonet(dot)com> |
---|---|
To: | andrew harvey <a(dot)andrewharvey(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Record Separator with psql -c when output to a variable not a file! |
Date: | 2010-10-04 21:22:54 |
Message-ID: | 4CAA45AE.50600@archonet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 04/10/10 20:51, andrew harvey wrote:
> The default psql -c record separator is a newline when output is the
> screen, console or a file. But what if I'm required to send output to
> a variable and not to a file (or standard output?)
>
> command="`psql -c "SELECT * FROM pg_stat_database`"
> I know that, obviously, if you output the result of the sql query to a
> file and then use grep and awk you could have wonderful output all the
> time. But there is a specific requirement here to do all the
> formatting from within a variable!
This probably won't work:
echo $command | cut -f 2,4,5
This probably will:
echo "$command" | cut -f 2,4,5
I hate shell - I always spend hours trying to get quoting to work properly.
Oh, for the archives Andrew is probably using a command like:
psql -t --no-align --field-separator=$'\011'
That turns the header and footer off (tuples only) and sets the output
to unaligned tab-separated columns.
--
Richard Huxton
Archonet Ltd
From | Date | Subject | |
---|---|---|---|
Next Message | Martijn van Oosterhout | 2010-10-04 21:23:07 | Re: Record Separator with psql -c when output to a variable not a file! |
Previous Message | Jeff Ross | 2010-10-04 21:08:08 | psql \q hang |