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