Reputation: 2574
I will be running a list of processes that will have the following naming conventions:
a_feed
b_feed
c_feed
...
I have written a bash shell script that will allow me to filter out the processes with these naming patterns. Please look at the one line in my shell script below:
ps -ef | grep -i *_feed | grep -v grep | awk '{print $2, " ", $8, " ", $10}'
For some reason, grep -i *_feed
is unable to find any process that conforms to the pattern *_feed
.
Does anyone have any ideas why?
Thanks.
Upvotes: 0
Views: 681
Reputation: 2017
I usually save the output of the list of processes in a shell
variable and then search for the matching lines as a new command. This avoids needing a grep -v
to remove the running grep
command.
I also match the lines inside awk
so that no grep
is needed at all. I think this is easier to read and understand:
p="$(ps -ef)"
echo "$p" | awk '/_feed/ {print $2, " ", $8, " ", $10}'
Upvotes: 0
Reputation: 195029
from grep man page:
-G, --basic-regexp Interpret PATTERN as a basic regular expression (BRE, see below). This is the default.
so, by default the pattern would be regular expression.
in your example, you could use grep -i ".*_feed"
Upvotes: 0
Reputation: 96258
*
need something in front of it.
Also, if you have a file with the pattern *_feed
in your working directory bash will do wildcard expansion.
Use:
grep -i '.*_feed'
Upvotes: 1
Reputation: 26699
grep users regular expression, in which * means matches 0 or more times
, and not any character
.
You should replace it with grep -i .*_feed
Upvotes: 3