Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove multiple lines from text file using grep

Tags:

grep

I would like to remove unwanted lines from my text file had certain words. i have use grep -v like this

grep -v 'error|fault|unkownn' input.txt > out.txt

it's working with one word but not on multiple words. did i miss anything?

like image 702
raindrop Avatar asked Jul 26 '26 17:07

raindrop


1 Answers

| is only treated as a a regex character when grep is working in extended regex mode. So you need to do one of the following:

# Escape the | so that it's treated as a regex control character
grep -v 'error\|fault\|unkownn' input.txt > out.txt

# -E enables extended regex mode
grep -vE 'error|fault|unkownn' input.txt > out.txt

# egrep = grep -E
egrep -v 'error|fault|unkownn' input.txt > out.txt
like image 79
Oliver Charlesworth Avatar answered Jul 28 '26 15:07

Oliver Charlesworth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!