Unix Command Grep output manipulation if no result is found

Asked

Viewed 181 times

1

Good morning!! I am creating a script and I need that when I do a grep on a line and do not find it it return me the parameter I searched!

grep "192.0.0.1 " /file.txt

In the.txt file it does not have the string "192.0.0.1 " I want it to return me "192.0.0.1 " for me to save in another file, I am not able to use diff because the pattern on each line in the file is different.

Thank you

1 answer

2

People I managed to solve this problem as follows!

grep -v '^#' < arquivo.com.o.que.procuro | while read line2; do

valor=$(grep -c "$line2 " arquivo.onde.estou.procurando)                     

if [ $valor -eq 0 ]; then          
   echo $line2 >> arquivo.onde.vai.salvar.o.que.nao.encontrou                     
   echo $line2 $valor "eh diferente"                            
 fi

done  

Browser other questions tagged

You are not signed in. Login or sign up in order to post.