How to write each record of the result of a sql query to a file, separated by a space in bash? How to write each record of the result of a sql query to a file on a separate line in bash?

  • 2
    never worked with postgres but I am sure that awk, sed + output redirection + xargs will help you - jmu

3 answers 3

psql dbname -c 'select * from test1' > file.txt 
     echo "SELECT * FROM table" | psql -Uuser -Wpassword dbname > file 

      mysql -h host -u user -e "SELECT account, shell FROM passwd" -ss namedb> shells.txt

      a source