Reputation: 1613
I'm running a psql
query like so:
$ psql --file=foo.sql "BAR-DB"
Where foo.sql
contains the query. foo.sql
has bad syntax, so the output is a list of error messages. My plan was to pipe the output to grep
so I can filter specific error messages, but
$ psql --file=foo.sql "BAR-DB" | grep PATTERN
doesn't seem to do anything. psql
's documentation shows the optional flag:
-o, --output=FILENAME send query results to file (or |pipe)
but I'm not sure how to use it to pipe the output to grep. What is the proper syntax?
Upvotes: 2
Views: 1842
Reputation: 43039
You could redirect the stderr of psql to stdout and then pipe it to grep:
psql --file=foo.sql "BAR-DB" 2>&1 | grep -- PATTERN
Upvotes: 3