Menu Close

Month: June 2016

Save psql query output to csv file

by stackoverflow.com

In terminal (while connected to the db) set output to the csv file

1) set field seperator to “;” by:

\f ';'

2) set output format unaligned:

\a

3) show only tuples

\t

4) set output

\o '/tmp/yourOutputFile.csv'

5) execute your query

select * from YOUR_TABLE

6) output

\o

you will be able to find your cvs file in this location

cd //tmp
copy it using scp command 

or edit using nano:

nano //tmp/yourOutputFile.csv

You can also print to console with \o again.

Remove untagged images from docker

by jimhoskins.com

In the process of running docker I accumulated several images that are not tagged. To remove these I use this command:

docker rmi $(docker images -a | grep "^" | awk '{print $3}')

This works by using rmi with a list of image ids. To get the image ids we call docker images then pipe it to grep “^”. The grep will filter it down to only lines with the value “” in the repository column. Then to extract the id out of the third column we pipe it to awk “{print $3}” which will print the third column of each line passed to it.