Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

315
Vistas
grep -f when the pattern file also has some empty lines

Is there any option of the grep command to suppress the effect of empty lines in the pattern file? I would prefer this option than always checking and filtering the nascent pattern file.

Here is an example (in pattern_file, there is an empty line):

$ cat pattern_file  
APPLE  

PEAR  
$ cat file  
Nothing  
fruit  
$ grep -f pattern_file file  
Nothing  
fruit
over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

To ignore empty lines in pattern file:

grep -f <(grep . pattern_file) file
over 4 years ago · Santiago Trujillo Denunciar

0

grep -v '^$'

This actually grabs all the lines except for newlines. You can pipe the result to your grep like this: grep -v '^$'| otherGrep

over 4 years ago · Santiago Trujillo Denunciar

0

About -f option:

A null pattern can be specified by an empty line in pattern_file.

So, it is a feature, and you should delete empty lines, e.g. with sed:

sed '/^$/d' | grep -f ...
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda