[SOLVED] > | bash help from expert

Posted on
Fri Apr 10, 2015 9:53 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

[SOLVED] > | bash help from expert

the following does not pipe correctly
Code: Select all
psql  -U userid  database  < inputFile 2>&1 | grep -v notWantedText > outputFile
outputFile is empty

this one prints correctly to the terminal
Code: Select all
psql  -U userid  database  < inputFile 2>&1 | grep -v notWantedText


It works in 2 steps:
Code: Select all
psql  -U userid  database  < inputFile > outF1  2>&1   (*)
cat outF1 | grep -v notWantedText > outputFile


I am stuck
any help from the "real" UNIX guys?

Karl

(*) the outF1 has to go before the 2>&1 .. learned that one.

good read : http://www.catonmat.net/download/bash-redirections-cheat-sheet.pdf
Last edited by kw123 on Fri Apr 10, 2015 11:29 am, edited 1 time in total.

Posted on
Fri Apr 10, 2015 11:28 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: > | bash help from expert

here the solution:

the output of
Code: Select all
psql  -U userid  database  < inputFile 2>&1 | grep -v notWantedText > outputFile
is buffered and it looked as if nothing was written... but waiting some time showed the output appearing in "outputFile"

Karl

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest

cron