This article mainly introduces the use of grep in Linux to filter multiple conditions and grep's common filtering commands. Friends in need can refer to it.
cat log.txt | grep condition;
cat log.txt | grep condition one | grep condition two;
cat log .txt | grep condition one | grep condition two | grep condition three;
grep condition one log.txt | grep condition two | grep condition three;
Don’t talk nonsense, for example, you need to exclude abc mmm in .txt nnn
grep -v 'mmm\|nnn' abc.txt
But there are still many, you need to find the required ip address from these pieces of information, We may have thought of using grep -v to block inet6. The results are as follows:
Recommended: [Linux Video Tutorial]
1、|bash-3.2# ifconfig | grep inet | grep -v inet6 2、| inet 127.0.0.1 netmask 0xff000000 3、| inet 10.60.104.38 netmask 0xfffffe00 broadcast 10.60.105.255
Let’s take a look at the common uses of linux grep Filtering command
The filtered content can be a phrase, etc., which needs to be wrapped in quotation marks
1. Get the keyword key in the file: cat fileName | grep "key"
2. Get a certain keyword key1, key2, key3 in the file: cat fileName | grep -E "key1|key2|key3"
3. Get multiple keywords in the file and satisfy the following requirements: cat fileName | grep key1 | grep key2| grep key3
4. Ignore a keyword in the file and need to convert Meaning "|": cat fileName | grep -v "key1\|key2\|key3"
This article comes from php Chinese website, linux system tutorial column, welcome study!
The above is the detailed content of How to use grep to filter multiple conditions in Linux. For more information, please follow other related articles on the PHP Chinese website!