0

This question already has an answer here:

I'm trying to extract the CMD column from a ps -fp <pid> command.

Now I know there are several ways to do this, some of which include:

$ cat /proc/<pid>/cmdline 

or

$ ps -p <pid> -o cmd

However, I wanted to know how it can be done using something like awk or cut. I managed to get a pretty straightforward solution with awk:

$ ps -fp <pid> | awk '{print $8}'

Which simply selects the CMD or the 8th column from the output of the ps command. My question is why doesn't the same idea work with cut?

I tried the following, but none of them seemed to work:

$ ps -fp <pid> | cut -f 8
$ ps -fp <pid> | cut -d $'\n' -f 8
$ ps -fp <pid> | cut -d ' ' -f 8
  1. How does cut read input differently than awk?

and

  1. Why does cut -d $'\n' -f 8 work but not cut -d '\n' -f 8?

marked as duplicate by Thomas Dickey, G-Man, slm Sep 3 '18 at 4:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Browse other questions tagged or ask your own question.