Home > Net >  Grep to exclude comment like -- with trailing spaces
Grep to exclude comment like -- with trailing spaces

Time:04-27

I have the regex:

grep -iE 'UTL_FILE[\. ]*(FCOPY|FGETATTR|FOPEN|FOPEN_NCHAR|FREMOVE|FRENAME|fopen)' 

And I would like to extend it to exclude all the lines which are comments starting with any number of withe spaces and '--'

For example, get the next line (This is already done by the regular expression):

 l_output := utl_file.fopen(p_RutaLocal, Nombre_Archivo,'w'); 

But ignore lines like this:

 --l_output := utl_file.fopen(p_RutaLocal, Nombre_Archivo,'w'); or
       --  l_output := utl_file.fopen(p_RutaLocal, Nombre_Archivo,'w'); 

CodePudding user response:

Pipe two greps together:

grep -v '^[[:space:]]*--' | grep -iE ...

The -v option prints lines that don't match.

CodePudding user response:

Suggesting to try:

 grep -Ev "[[:space:]]*--"|grep -iE 'UTL_FILE[\. ]*(FCOPY|FGETATTR|FOPEN|FOPEN_NCHAR|FREMOVE|FRENAME|fopen)' 
  • Related