Вывод разделения команды столбцами с помощью Bash?

Ну, если мы предполагаем, что добавить/подотследить операция стоит 1, затем умножьте затраты 5 и разделите затраты приблизительно 20.

81
задан jww 20 September 2019 в 22:17
поделиться

5 ответов

One easy way is to add a pass of tr to squeeze any repeated field separators out:

$ ps | egrep 11383 | tr -s ' ' | cut -d ' ' -f 4
160
ответ дан 24 November 2019 в 09:26
поделиться

try

ps |&
while read -p first second third fourth etc ; do
   if [[ $first == '11383' ]]
   then
       echo got: $fourth
   fi       
done
3
ответ дан 24 November 2019 в 09:26
поделиться

Getting the correct line (example for line no. 6) is done with head and tail and the correct word (word no. 4) can be captured with awk:

command|head -n 6|tail -n 1|awk '{print $4}'
1
ответ дан 24 November 2019 в 09:26
поделиться

Instead of doing all these greps and stuff, I'd advise you to use ps capabilities of changing output format.

ps -o cmd= -p 12345

You get the cmmand line of a process with the pid specified and nothing else.

This is POSIX-conformant and may be thus considered portable.

0
ответ дан 24 November 2019 в 09:26
поделиться

I think the simplest way is to use awk. Example:

$ echo "11383 pts/1    00:00:00 bash" | awk '{ print $4; }'
bash
64
ответ дан 24 November 2019 в 09:26
поделиться
Другие вопросы по тегам:

Похожие вопросы: