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

177
Visualizações
grep AND Operations

I want to simulate AND operation in grep . List all the file files contains "Some Words" and contain "Some Other Words" anywhere in the file.

So far I tried #

egrep  -lir '(Some Words)(Some Other Words)' *.myfiles

but it is not working.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Using GNU tools:

grep -lirZ string1 . | xargs -d '\0' grep -li string2
  • The first grep lists files (-l) containing string1
  • -i: case insensitive, -r: recursive, -Z: file list delimited by ascii null (a safe delimiter for file names)
  • Pipe the list to xargs, with null delimiter, to pass it to the second grep
  • The second grep filters the list for files containing string2
  • . refers to the current directory, which is searched recursively
over 4 years ago · Santiago Trujillo Relatório

0

By definition grep is a tool looking for patterns line by line and printing the matching ones, as stated in its man page. There is no way to grep on multiple lines with a single grep, unless doing as stated in Dan's answer where you use grep together with GNU tools.

If instead we want to grep on the same line and the order in which "Some Words" and "Some Other Words" doesn't matter, you can run the following command:

egrep -lir "(Some Words.*Some Other Words)|(Some Other Words.*Some Words)"

If the order matters, then in the command above just remove the wrong order. For example if the right order is first "Some Words" and then "Some Other Words" the command should look like:

egrep -lir "Some Words.*Some Other Words"
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