Re: [HACKERS] How would I get rid of trailing blank line?

From: "Tena Sakai" <tsakai(at)gallo(dot)ucsf(dot)edu>
To: "Andrew Dunstan" <andrew(at)dunslane(dot)net>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, <scott(dot)marlowe(at)gmail(dot)com>
Cc: <pgsql-sql(at)postgresql(dot)org>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] How would I get rid of trailing blank line?
Date: 2009-04-03 05:52:09
Message-ID: FE44E0D7EAD2ED4BB2165071DB8E328C04E84A67@egcrc-ex01.egcrc.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-sql

Hi Andrew,

> Right. There's a simple pipeline way to get rid of it:
> psql -t -f query.sql | sed -e '$d' > query.out

Hi Scott,

> Tired of those blank lines in your text files? Grep them away:
> psql -tf query.sql mydatabase | grep -v "^$" > query.out

Thank you Both.

Regards,

Tena Sakai
tsakai(at)gallo(dot)ucsf(dot)edu

-----Original Message-----
From: Andrew Dunstan [mailto:andrew(at)dunslane(dot)net]
Sent: Thu 4/2/2009 6:34 PM
To: Tom Lane
Cc: Tena Sakai; pgsql-sql(at)postgresql(dot)org; pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] [SQL] How would I get rid of trailing blank line?

Tom Lane wrote:
> "Tena Sakai" <tsakai(at)gallo(dot)ucsf(dot)edu> writes:
>
>> I often use a line like:
>> psql -tf query.sql mydatabase > query.out
>>
>
>
>> -t option gets rid of the heading and count
>> report at the bottom. There is a blank line
>> at the bottom, however. Is there any way to
>> have psql not give me that blank line?
>>
>
> Doesn't look like it --- the final fputc('\n', fout); seems to be
> done unconditionally in all the output formats. I wonder if we should
> change that? I'm afraid it might break programs that are used to it :-(
>
>
>

Right. There's a simple pipeline way to get rid of it:

psql -t -f query.sql | sed -e '$d' > query.out

cheers

andrew

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Itagaki Takahiro 2009-04-03 07:23:10 Re: Duplicate key value error
Previous Message Heikki Linnakangas 2009-04-03 05:48:44 Re: a few crazy ideas about hash joins

Browse pgsql-sql by date

  From Date Subject
Next Message Adrian Klaver 2009-04-03 13:28:54 Re: Text cast problem
Previous Message Scott Marlowe 2009-04-03 02:53:37 Re: How would I get rid of trailing blank line?