0

When i use : ps -o user,cmd My output is :

User    CMD
0        in.telnetd
0        sh
0        processd
0        processe
0        in.telnetd
0        -sh
0        top

I want to get 2 row (which contains processd & processe) after i do grep command .

What i used :

 1.   ps -o user,cmd | grep "processd\|processe"
 2.   ps -o user,cmd | grep processd | grep processe

Am i using correct format to grep what i want or is it like i need to modify my query ?

0

3 Answers 3

1

one way would be:

ps -o user,cmd | grep "process[de]"

of course you might end up catching also lines like

0        /some/other/app --with --lots of arguments including also processe

to make sure you do not catch that, you should probably use awk.

Sign up to request clarification or add additional context in comments.

Comments

1

You were looking for

ps -o user,cmd | egrep "processd|processe"

When I need to check logfiles, I use something similar:

interesting="keyword1"
interesting+="|key2
interesting+="|key3"
skip="garbage1"
skip+="|garb2"
skip+="|garb3"

grep "^20150909" logfile | egrep "${interesting}" | egrep -v "${skip}"

1 Comment

Have a vote. Just FYI, I think those modern, POSIX-y folk are getting rid of egrep and suggesting we use grep -E instead.
1

[SOLVED]

After some trial and error i just got to know about -E option .

ps -o user,cmd | grep -E processd\|processe

1 Comment

For your information: there are three grep-like commands: the regular grep (which uses normal regular expressions), fgrep or grep -F (which uses fix strings) and egrep or grep -E (extended grep, which makes it possible to combine different regular expressions).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.