I'm running

psql -U postgres template1 -c "select * from pg_stat_activity"

and the output is too wide for my terminal. Is there a *nix command I can use to prevent the output from wrapping? Maybe a setting in screen that enables virtual horizontal scrolling?

link|improve this question

64% accept rate
feedback

4 Answers

up vote 7 down vote accepted

Try

psql ... | less -S

The -S option to less enables horizontal scrolling instead of line wrapping.

link|improve this answer
1  
Note that you can still scroll horizontally without -S. When scrolled to the first column it will wrap, but once you scroll right the text will be "unwrapped". – Ignacio Vazquez-Abrams Apr 17 '10 at 3:34
Interesting, I never noticed that. – David Zaslavsky Apr 18 '10 at 0:05
feedback

If you don't want to (or can't) use a pager for some reason, you can also use cut:

psql ... | cut -c1-60

This takes only the first 60 characters of each line. No scrolling however.

link|improve this answer
feedback

fmt is probably what you want; it will wrap lines at a given column. pr has more options and is more complex.

link|improve this answer
feedback

Consider adding -P format=wrapped to your psql invocation, if you're using pg 8.4 or newer.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.