Reed_Xia Reed_Xia - 1 month ago 16
Bash Question

How to remove the lines contain certain string using Shell?

I'm using Ubuntu to run an automation test, it need process a text log file, such as following

INVITE INVITE sip:88787@10.1.1.100:5060 SIP/2.0
INVITE SIP/2.0 100 Trying
1154845 NOTIFY NOTIFY sip:1@10.1.1.19:5065 SIP/2.0
1154845 NOTIFY NOTIFY SIP/2.0 200 OK
INVITE SIP/2.0 180 Ringing


I want to just remove the 2 lines with "NOTIFY" and get log file below, I'm new to Shell and tried some google but didn't figure out the way, can you please share how to do that? Thanks!

INVITE INVITE sip:88787@10.1.1.100:5060 SIP/2.0
INVITE SIP/2.0 100 Trying
INVITE SIP/2.0 180 Ringing

Answer

Try the following:

grep -v "NOTIFY" filename.txt

Grep is commonly used to print lines that match a certain pattern, but the "-v" option allows for inverting the match; removing lines that match the pattern.

More information can be found here.