3

I'd like to specify the column-separator

ps -o "%a|%p"        # separator |

and the column-width

ps -o cmd:50,pid     # width 50 for cmd

in one command. Is this possible??

It is not about the column-width but I'd like to have the full length command even if it is not the last column.

  • should it cover any number of columns with possibility to set width for a certain column? – RomanPerekhrest Jan 20 '18 at 13:30
  • I need the FULL command and the PID. The command should be 1st. – chris01 Jan 20 '18 at 13:33
3

The -o command is additive, so just do multiple of those:

ps -a -o "cmd:50 " -o "|%p"
CMD                                               |  PID
/usr/lib/gnome-session/gnome-session-binary --auto| 4158

The problem is that you'll get some whitespace around the PID as its right-justified. You can see the 4158 above has a space after the pipe.

| improve this answer | |
4

I need the FULL command and the PID. The command should be 1st.

As you need to adjust the output for just 2 columns in predefined order (cmd and pid)
here's ps + sed "trick":

ps -ao "cmd:50,pid" | sed 's/./&|/51'

Test output:

CMD                                                |  PID
nano jq1 -c                                        | 6041
man ps                                             |13714
pager                                              |13725
ps -ao cmd:50,pid                                  |13950
sed s/./&|/51                                      |13951
python                                             |15345
bash -v                                            |16513
bash +v                                            |16645
top                                                |22426
awk -F| -v cmd=xmlstarlet ed -L -u "//Add/value[%d |31412
sh -c xmlstarlet ed -L -u "//Add/value[1]/@IP" -v  |31413
xmlstarlet ed -L -u //Add/value[1]/@IP -v 1.1.1.1  |31414
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.