Alejandro Espinosa
Alejandro Espinosa

Reputation: 3

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/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

Upvotes: 0

Views: 5156

Answers (4)

hluk
hluk

Reputation: 6016

Maybe this:

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

Upvotes: 0

Adam Schmideg
Adam Schmideg

Reputation: 10850

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

Upvotes: 1

hellvinz
hellvinz

Reputation: 3500

what about this:

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

Upvotes: 0

Cfreak
Cfreak

Reputation: 19309

You don't need cut:

ps -ao command | grep g

Upvotes: 0

Related Questions