Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker -ps --format output with substr

There is a command: docker ps --format "{{.ID}}\t{{.Command}}" --no-trunc (used https://pkg.go.dev/text/template)

which outputs the full text of the '{{.Command}}' (which I need), but outputs too long '{{.ID}}'

I need to take the first 12 characters from '{{.ID}}' and all characters (--no-trunc) from '{{.Command}}'. How to do it?

like image 543
Avraam Avatar asked Sep 15 '26 12:09

Avraam


1 Answers

You can use the ´printf` function in the Go template like this

docker ps --format "{{printf \"%.12s\" .ID}}\t{{.Command}}" --no-trunc
like image 162
Hans Kilian Avatar answered Sep 18 '26 05:09

Hans Kilian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!