0

I have this output and want to extract the IMAGE ID from it

$ podman image ls | grep youtube-dl
localhost/youtube-dl          latest           2d4e37c4d609  3 hours ago    205 MB

All I know piping this to cut -f3 should to this but doesn't. The output is actually identical. All examples for cut I've found tell me that a tab (which applies here I believe) is assumed as delimiter.

Can anybody kindly point me to the right direction in this? Maybe I am falsely assuming the output uses tabs. I couldn't say what else however

vrms
  • 287
  • 1
  • 7
  • 17

2 Answers2

2

Are you sure this out is tab delimited?
That would be quite unusual in a linux environment - whitespace delimiting is far more common.

Use one of the "awk" family of tools instead:

$ podman image ls | gawk '/youtube-dl/{print $3;}'
2d4e37c4d609
Phill W.
  • 1,479
  • 7
  • 7
  • tx, that works. Never heard of those till today. Seems another field I have to explore. – vrms May 17 '22 at 14:24
0

There are many ways to do this. For instance, you can pipe your command output through cut while modifying the fiealds delimiter:

$ podman image ls | grep grep youtube-dl | tr -s ' ' | cut -d\ -f3

It is also possible to reveal the delimiter being used (e.g. TAB or space) by piping the output through od as in:

$ podman image ls | grep grep youtube-dl | od -An -c

  • 3
    `cut -d" " -f3` doesn't work unless you squeeze the whitespace first: cut does not consider _sequences_ of the delimiter. `... | tr -s '[:blank:]' | cut -d" " -f3` – glenn jackman May 17 '22 at 15:32
  • 1
    You are right about having delimiter sequences; they must be removed if any. I'll update, but target the space character only, i.e., not using the entire class. – Brahim Gaabab May 17 '22 at 19:20
  • this `$ podman image ls | grep grep youtube-dl | tr -s ' ' | cut -d\ -f3` does exactly what I was looking for, thx @BrahimGaabab @glenn_jackman (just as the `gawk` solution further up north). – vrms May 18 '22 at 13:32