开发者

Regex process using cut(Linux)(sh)

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/g开发者_StackOverflow社区etty -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


You can't split with cut on a regex, a group of spaces in this case. You can either cut from a certain bytes, or cut by a single character delimiter. So you can do

ps aux | cut -b66- | grep g


You don't need cut:

ps -ao command | grep g


what about this:

ps -o "comm" -A | grep -E "^g"


Maybe this:

ps -eo command | grep -E '^(|\S*/)g'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜