Created
November 25, 2014 03:31
-
-
Save ramkumardevanathan/d25bb91d8ab170d3b656 to your computer and use it in GitHub Desktop.
simple gist to get docker ps output as csv file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker ps -a --no-trunc | awk -F " +" '{$1=$1}1' OFS="\t" |
@matteo-bombelli
There is a bug in your script. CONTAINER ID
turns into CONTAINER,ID
which is undesireable
Also, the created fields like "5 weeks ago" becomes three different fields (5,weeks,ago)
This is the trick --format
with \t
on docker container ls
and grab that on awk
with -F '\t'
docker container ls --no-trunc -a --format='"{{.Names}}"\t"{{.Image}}"\t"{{.Ports}}"\t"{{.Status}}"' | awk -F '\t' '{$1=$1}1' OFS=","
Note that quoted values provided from --format
, good to avoid undesired fields split.
Of course a better way is without awk
, in this case a simple:
docker container ls --no-trunc -a --format='"{{.Names}}","{{.Image}}","{{.Ports}}","{{.Status}}"'
References:
https://docs.docker.com/engine/reference/commandline/ps/#format
https://stackoverflow.com/questions/5374239/tab-separated-values-in-awk
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hey very good!
but this is a tsv (tab separated values), csv (comma separated values) is:
docker ps -a --no-trunc | awk -F " +" '{$1=$1}1' OFS=","
but thank you very much!