For ex, a file contain contents:
10.45.56.84 raj
10.49.31.81 mum
10.49.31.86 mum
10.81.51.92 guj
10.45.56.116 raj
10.45.56.84 raj
I want to search 10.45.56.84
and 10.81.51.92
in the above file and delete line if pattern matches.
Also i want to do this in single command.
Another solution:
awk '!/10.45.56.84|10.81.51.92/' file
grep -Fv -f <(echo $'10.45.56.84\n10.81.51.92') filename
You could do this:
sed -e '/10[.]45[.]56[.]84/d;/10[.]81[.]51[.]92/d' file
This has two sed "d" delete commands separated by a semicolon. However, they are only executed if they match the respective pattern enclosed between slashes that come before eachcommand.
You can also use grep:
grep -Ev '10[.]45[.]56[.]84|10[.]81[.]51[.]92' file
The "-v" flag tell grep to print only the lines that don't match the pattern, and we use the OR operator "|" to match either pattern. The "-E" flag is used so we don't have to escape the OR operator with a backslash.
In both cases we place the period between brackets because otherwise the period is used as an operator that matches any character. You may place more characters inside a single pair of brackets, and they will be interpreted as to match one of the characters specified.
Hope this helps =)
This might work for you (GNU sed):
sed -r '/10\.(45\.56\.84|81\.51\.92)/d' file
awk -F " " '{if($1 != "10.45.56.84") if($1 != "10.81.51.92" ) { print $0;}}' inputFile > OutputFile
Explanation :
awk : Awk is a scripting language used for manipulating data and generating reports.
" " : its is used for delimiter. if data is separated by | then need to mention like "|"
{if($1 != "10.45.56.84") if($1 != "10.81.51.92" ) { print $0;}}' : pattern(Conditions) and print in outputFile