Grep all lines with the string "TNS-" but skip those with "TNS-12514"

Platform: Oracle Linux 6.3

From a log file, I want to grep all lines with the pattern "TNS-" but I want to skip those with the pattern "TNS-12514" . How can I do this ?

You can use -v option to exclude any pattern

grep "TNS-" file.log | grep -v "TNS-12514"
1 Like

Like this ?

 awk '/TNS-/ && !/TNS-12514/' inputfile
cat inputfile
his this is TNS- how
whts is
anyway TNS-12514 this
starnge TNS-456 let tr
output:
his this is TNS- how
starnge TNS-456 let try
1 Like
perl -ne 'print if /TNS-(?!12514)/' yourfile