pcregrep with multiple capturing groups
The ability to specify -o
multiple times to pcregrep
appears to be a very recent development (version 8.32, released 30 November 2012). I'll assume your distro doesn't have this yet. :-) So, using awk
instead. Also, replacing extraneous use of tail
in the original with equivalent functionality in the first awk
script.
docker ps | awk '(NR >= 2) { print $1 }' | xargs docker inspect | awk '($1~/"ID":/){gsub("\"|,","",$2);id=$2}; (id && $1~/"HostPort":/) {gsub("\"","",$2);print id " " $2;id=""}'