Score:0

how to extract a certain field from standard output with cut?

de flag

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

Score:2
cn flag

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
vrms avatar
de flag
tx, that works. Never heard of those till today. Seems another field I have to explore.
Score:0
pl flag

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

fo flag
`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`
pl flag
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.
vrms avatar
de flag
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).
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.