2

I need to find all processes that have in their names a number between 100 and 200 inclusive.

I tried

ps -ef | grep xclock -bw '[1-2][0-9][0-9]' 

but that includes 299. How to suppress it and have only numbers up to 200?

8
  • 2
    grep '1[0-9][0-9]\|200' ? Commented Jun 22, 2015 at 11:59
  • Why you need the sign \ ? Commented Jun 22, 2015 at 12:02
  • 1
    And thank you!!! I did not think about this option :) Commented Jun 22, 2015 at 12:03
  • So it is not interperetted as a literal | and instead is seen as the or operator. And no problem, glad you got it sorted :) Commented Jun 22, 2015 at 12:03
  • What grep implementation is that? With GNU grep, that would search with byte offset the xclock word in the file called [1-2][0-9][0-9]. With all other grep implementations that I know, it would search for xclock in the -bw and [1-2][0-9][0-9] files. Commented Jun 22, 2015 at 13:13

1 Answer 1

2

I like to directly use proc for that

grep -l '1[0-9][0-9]\|200' /proc/[1-9]*/comm|awk -F '/' '{print $3}'

For the pid variant

grep -l 'xclock' /proc/{1[0-9][0-9],200}/comm 2>/dev/null|awk -F '/' '{print $3}'

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.