pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Greg Smith <greg@2ndquadrant.com>
To: Tena Sakai <tsakai@gallo.ucsf.edu>
Cc: Gabriele Bartolini <gabriele.bartolini@2ndQuadrant.it>
Cc: pgsql-admin@postgresql.org <pgsql-admin@postgresql.org>
Subject: Re: What is field separator?
Date: Mon, 31 May 2010 23:07:57 -0400
Message-ID: <4C04798D.70606@2ndquadrant.com> (raw)
In-Reply-To: <C829B239.AF3B%tsakai@gallo.ucsf.edu>
References: <C829B239.AF3B%tsakai@gallo.ucsf.edu>

Tena Sakai wrote:
>   $ echo "select marker, p, afreq from gallo.fbat_sdsdecode limit 10" | \
>  > psql -P 'format=unaligned' -P 'fieldsep=\t' -t -f - musket
> What's denoted as \t is not a tab character.  It is a two character
> sequence backslash followd by a t.  I have tried all other possibilities
> such as \\t , "\t", etc that I can think of, but I cannot get an honest to
> god tab character to appear as field separator. 

Yeah, that's a tough one.  In bash you can use ANSI C quoting to pull 
this off:

psql -c "select name,setting from pg_settings limit 1" -d postgres -At 
-F $'\t'

See http://wiki.bash-hackers.org/syntax/quoting for more information.  
Portability to other shells I'm not sure about.

Note that I did two other things a little differently than your example, 
as well as tightening up the abbreviations:

-Putting the command in -c " " is just better all around than piping 
into psql using echo.  It even works with multi-line input, i.e.:

psql -c "
select 1
"

-Explicitly specifying the database manually using -d makes what's 
happening easier to follow than expecting people to know the convention 
that the first non-option passed to psql is a database name.

-- 
Greg Smith  2ndQuadrant US  Baltimore, MD
PostgreSQL Training, Services and Support
greg@2ndQuadrant.com   www.2ndQuadrant.us




view thread (10+ messages)  latest in thread

Message-ID: <4C04798D.70606@2ndquadrant.com>
Permalink:  ../4C04798D.70606@2ndquadrant.com/
Also on:    postgresql.org/message-id/4C04798D.70606@2ndquadrant.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: greg@2ndquadrant.com, tsakai@gallo.ucsf.edu, gabriele.bartolini@2ndQuadrant.it
  Subject: Re: What is field separator?
  In-Reply-To: <4C04798D.70606@2ndquadrant.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox