Unix Grep command handling the output if there is no result

1

Good morning !! I'm creating a script and I need when I make a grep on a line and can not find it, it returns the parameter I looked for!

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 "192.0.0.1" for me to save to another file, I am not able to use diff because the default on each line in the file is different.

Thank you

    
asked by anonymous 12.02.2018 / 14:39

1 answer

2

I was able 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  
    
13.02.2018 / 16:33