I need a way to simplify this command:
grep SEARCHTERM server.log | grep -v PHHIABFFH | grep -v Stats
It should find all the lines including SEARCHTERM
but exclude if one of the SEARCHTERM
lines includes PHHIABFFH
or Stats
.
I need a way to simplify this command:
grep SEARCHTERM server.log | grep -v PHHIABFFH | grep -v Stats
It should find all the lines including SEARCHTERM
but exclude if one of the SEARCHTERM
lines includes PHHIABFFH
or Stats
.
This will work:
grep SEARCHTERM server.log | grep -Ev PHHIABFFH|Stats
Why do you want to simplify this pipe? Un*x commandline tools are made to be chained in a way like this.
Edit
Some of answers suggest using features of specific versions of grep. I like this but it is very possible that such specific features are not present in the version of grep used by the OP.
So as long as we don t know what environment the OP has and what version of which tool he can use I suggest to stick to the common features present in all versions of the tools used.
This again nicely illustrates the Un*x philosophy.
It s easy to underestimate the power of combining pipes and redirection. As an instructive example, The Unix Shell As a 4GL [Schaffer-Wolf] shows that with these facilities as a framework, a handful of simple utilities can be combined to support creating and manipulating relational databases expressed as simple textual tables.
http://www.catb.org/~esr/writings/taoup/html/ch07s02.html#plumbing
If simple means just one command with more args ...
awk $0 !~ /PHHIABFFH|Stats/ && /SEARCHTERM/ server.log
you can just use the shell
while read -r line
do
case "$line" in
*"Stats"*|*"PHHIABFFH"*) continue;;
*"SEARCHTERM"* ) echo "$line";;
esac
done < "file"
I would have just done this:
grep SEARCHTERM server.log | grep -v -e PHHIABFFH -e Stats
Recently I discovered two amazing regular expression features: ?: and ?!. I was curious of other neat regex features. So maybe you would like to share some tricky regular expressions.
I need to remove image tags from text, so both versions of the tag: <img src="" ... ></img> <img src="" ... />
How do I, using preg_replace, replace more than one underscore with just one underscore?
I was trying to write a regexp to replace all occurrences of with unless the is already preceeded immediately by a . I m doing this in Ruby 1.8.6 which doesn t support look behind in ...
Specifically, I have an array of strings called val, and want to replace all instances of "%{n}%" in the input with val[n]. More generally, I want the replace value to be a function of the match ...
I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...
I m building a lexical analysis engine in c#. For the most part it is done and works quite well. One of the features of my lexer is that it allows any user to input their own regular expressions. This ...
I need a regex for four-digit numbers separated by comma ("default" can also be a value). Examples: 6755 3452,8767,9865,8766,3454 7678,9876 1234,9867,6876,9865 default Note: "default" ...