Issue
shell scripting to print output with comma delimter instead of tab delimter for listing docker services
docker ps -a | awk -F \t '{print $1","$2","$3","$4","$5","$6","$7","$8}'
present output
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
35fe9af4efa0 thomsch98/kafdrop:latest "/usr/local/bin/mvn-…" 3 days ago Exited (137) 3 days ago PAServices_kafdrop.1 x2r2tuosozdd9uzfnq7ejdi70
Required output,
CONTAINER ID,IMAGE,COMMAND,CREATED,STATUS,PORTS,NAMES
8c0e092b6815,thomsch98/kafdrop:latest,"/usr/local/bin/mvn-…",3 days ago,Up 3 days,PAServices_kafdrop.1,yen4hgju18kkfgq9bvud7e1w8
Solution
Don't use awk and use the built in filter options of docker-ps
docker ps --format "{{ .Image }},{{.ID}},{{.Command}},{{.CreatedAt }},{{.Status }},{{.Ports }},{{.Names}}"
To retain the headers, add table:
docker ps --format "table {{ .Image }},{{.ID}},{{.Command}},{{.CreatedAt }},{{.Status }},{{.Ports }},{{.Names}}"
Answered By - Raman Sailopal Answer Checked By - Clifford M. (WPSolving Volunteer)