簡體   English   中英

如何使用 awk 命令從 docker ps 結果中僅獲取三列和值

[英]How to use awk command to get only three column and values from docker ps result

[centos@exe93-aws-mum:/exedge-volume/exedge]# docker ps | awk '{print $2,$5}'
ID CREATED
docker.elastic.co/beats/filebeat:7.9.1 minutes
gcr.io/ec2nf-256816/n3iwf-nwu:v2.0.0-992f54d minutes
gcr.io/ec2nf-256816/upf-ids:stg.misp-rule-integ-cb264cc minutes
gcr.io/ec2nf-256816/upf-fpm:at.r2.3.2 minutes
gcr.io/ec2nf-256816/upf-dns:v2.0.0-b4057d4 minutes
redis minutes
gcr.io/ec2nf-256816/exe-health:at.r2.3.1 minutes
prom/alertmanager:latest 5
prom/prometheus:latest 5
prom/node-exporter:latest 5
95713166e223 4
3f822532aac3 weeks

''值不是從特定列中獲取的,總值也不是相同的。 你能幫我解決這個問題嗎? 提前謝謝!''

您不需要使用 awk,使用 docker-ps 格式標志:

docker ps --format "{{.Image}}: {{.RunningFor}} {{.Names}}"

您還可以使用 jq 將 output 格式化為 json。

 docker ps --format "{ \"image\": \"{{.Image}}:\", \"Running\": \"{{.RunningFor}}\", \"Names\": \"{{.Names}}\" }" | jq -r

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM