0

I'm having a problem with regex in using the command sh cute, the problem is that I want to show all processes that start with g and just show the command, but do not know, help me please?

To do this I use the command:

ps aux | grep g 

but this show all process who contains the letter g and i need who start with g and cut the command to get this, for example i get a output of ps

root      1012  0.0  0.0   6128   644 tty4     Ss+  16:10   0:00 /sbin/getty -8 38400 tty4

1000 4571 0.0 0.0 12724 868 pts/4 S+ 19:21 0:00 grep --color=auto g

And I need get only /sbin/getty because is in path and the command grep. In definite get all files start with g and cut and cut above so that it is the command and attributes PD: I need use to get all with the commands grep and cut, and i can't don't use the pgrep.

Thanks in advance

4

4 回答 4

1

您不能cut在正则表达式上拆分,在这种情况下是一组空格。您可以从某个字节剪切,也可以按单个字符分隔符剪切。所以你可以做

ps aux | cut -b66- | grep g
于 2010-09-22T17:54:09.283 回答
0

那这个呢:

ps -o "comm" -A | grep -E "^g"
于 2010-09-22T17:51:19.943 回答
0

也许是这样:

ps -eo command | grep -E '^(|\S*/)g'
于 2010-09-22T18:10:08.717 回答
0

你不需要削减:

ps -ao command | grep g
于 2010-09-22T17:39:24.850 回答