cut with tr

question: delete docker images with none tag.

sample output:

hfyin@hfyin-VirtualBox:~/projects$ docker image ls | grep none
<none>      <none>              9df7104f4ba5        2 months ago        109MB
<none>      <none>              b003f9ad8bca        2 months ago        109MB

normally with cut command, i can get image id, but this time it fail due to the output has multiple blankspace. The solution is firstly replace repeated space with only one space using tr command, then use cut command.

$ docker image ls | grep none | tr -s ' ' | cut -d' ' -f3
9df7104f4ba5   

then to delete docker image using xargs as:

$ docker image ls | grep none | tr -s ' ' | cut -d' ' -f3 | xargs docker image rm

refer:

https://stackoverflow.com/questions/4367304/unix-need-to-cut-a-file-which-has-multiple-blanks-as-delimiter-awk-or-cut

发布了34 篇原创文章 · 获赞 0 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/hfyinsdu/article/details/104516460
tr
今日推荐