1

I need to silence the output of \x on in the command below:

$ psql foo_db -c '\x on' -c 'SELECT * FROM bar'

So instead of seeing this:

Expanded display is on.
-[ RECORD 1 ]
foo | lorem ipsum
bar | dolor
baz | sit_amet

I only see:

-[ RECORD 1 ]
foo | lorem ipsum
bar | dolor
baz | sit_amet

Thanks

leetbacoon
  • 1,111
  • 2
  • 9
  • 32
  • 1
    Hummm... `tail -n +2`? Or maybe `psql -x...`? – Poshi Sep 20 '19 at 10:14
  • @Poshi `tail -n +2` does work, however there may be situations where I need to silence output that's not at the very top, and with a varying number of rows in a table possibly above that, it would be difficult to remove that one line in a big load of information. `-x` also seems to work, but will only do the trick for `-x on`. Other output, i.e. `INSERT 0 1` for a specific line, may be different. – leetbacoon Sep 20 '19 at 10:17
  • To avoid those `INSERT 0 1` messages, please check https://stackoverflow.com/questions/21777564/postgresql-is-there-a-way-to-disable-the-display-of-insert-statements-when-rea – Poshi Sep 20 '19 at 13:21

1 Answers1

1

The easiest way would be to avoid that command entirely by setting the display mode using the proper command line flags:

$ psql -x foo_db -c 'SELECT * FROM bar'

But if you really want to hide an output instead of preventing it from appearing, you could just ignore the first line of output:

$ psql foo_db -c '\x on' -c 'SELECT * FROM bar' | tail -n +2

Or grep it out:

$ psql foo_db -c '\x on' -c 'SELECT * FROM bar' | grep -v "Expanded display is on."

But those seems ugly to me.

Poshi
  • 5,332
  • 3
  • 15
  • 32
  • Hmmm, good answers. `-x` sounds most reliable in this situation. However, if I need to slience specific input elswhere that may pose a challenge – leetbacoon Sep 20 '19 at 10:19