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

184
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 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