Menu

Dipesh Majumdar

Blog and Paintings

Difference between awk and cut

$ docker images |grep simplev01
dipeshm77-ubuntu                                        simplev01                e5337522d045        About an hour ago   210MB
ubuntu                                                  simplev01                e5337522d045        About an hour ago   210MB
dipeshm77/ubuntu                                        simplev01                e5337522d045        About an hour ago   210MB

In the above query result if i want only the image-id of docker we can use awk

$ docker images |grep simplev01 |awk -F ' ' '{print $3}'
e5337522d045
e5337522d045
e5337522d045

"cut -d" can also be tried but it doesn't give the desired result - 

$ docker images |grep simplev01 |cut -d ' ' -f 3

<<<<no output here... which is because of unnecessary spaces that spoils the show>>>>>>

Get rid of unnecessary spaces:
$ docker images |grep simplev01 | tr -s ' '
dipeshm77/ubuntu simplev01 e5337522d045 About an hour ago 210MB
dipeshm77-ubuntu simplev01 e5337522d045 About an hour ago 210MB
ubuntu simplev01 e5337522d045 About an hour ago 210MB

Now "cut -d" gives the desired result

$ docker images |grep simplev01 | tr -s ' '  |cut -d ' ' -f 3
e5337522d045
e5337522d045
e5337522d045

 

 

Go Back

Comment