Search code examples
dockerterminalpipecut

Piping docker network ls to cut


I don't understand why

docker network ls | cut -f2

has no effect on the output of docker network ls. The output seems to be delimited by tabs. I would expect

NETWORK ID          NAME                DRIVER              SCOPE
5e2e0d7c6daf        bridge              bridge              local
5012d9100982        host                host                local
9574504d9579        test_default        bridge              local
0f7083dc1db7        php_fpm             bridge              local

to output

NAME             
bridge         
host    
test_default
php_fpm

Solution

  • The default delimiter of cut is tab, and only one character allowed in cut, so it cannot meet your requirements, suggest to use awk:

    docker network ls | awk -F'  +' '{print $2}'
    

    Sample output:

    NAME

    bridge

    dashboard_default

    host

    none