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

176
Visualizações
How to remove all instances of a string from output in linux terminal commands

This command almost does everything I am needing

cat /etc/passwd | cut -f6- -d : | sort | uniq 

but I can't figure out how to sort out a specific string

I need to remove "/remove/this" from any line where it occurs and I need the lines of text not to be broken up for 1 word per line.

The purpose of the command is List all of the shells used by at least one user on the system, without duplicates.

Wold appreciate any input.

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

0

You can use sed. When the pattern you are looking for contains /, you should use a different separator character. I find : quite readable.

cat /etc/passwd | cut -f6- -d : | sort | uniq | sed s:/remove/this::

Since sed will change some lines, it's better to move sort + uniq to the end of the pipeline. sort -u combines both programs.

cat /etc/passwd | cut -f6- -d : | sed s:/remove/this:: | sort -u
over 4 years ago · Santiago Trujillo Relatório

0

You can use a single awk command for that:

awk -F: '{sub(/\/remove\/this/, "", $NF);a[$NF]} END{for(i in a){print i}}' /etc/passwd

-F: splits the line by :.

The first block runs on every line of input while sub(/\/remove\/this/, "", $NF) removes the string from the last column and a[$NF] creates and index for every shell found in passwd. Obviously if the index already exists, it will not get created again. Doing so we dedup the data.

At the END of input we are iterating trough the array a and print every index: {for(i in a){print i}}

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