Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

314
Visualizações
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 Respostas
Responde à pergunta

0

To ignore empty lines in pattern file:

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

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda