1. xargs
docker ps -a | grep -v "CON" | awk '{print $1}' | xargs
2. sed
docker ps -a | grep -v "CON" | awk '{print $1}' | sed ':a; N;s/\n/ /; ta'
N 代表两行合并一行,中间用\n替换, :a 做个标记, ta代表命令执行成功后会跳转到 :a, 所以这句话就是循环执行 N 并\n替换为空格来达到合并成一行的目的.
3.tr
docker ps -a | grep -v "CON" | awk '{print $1}' | tr "\n" " "