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

231
Vistas
Remove eveything before including colon and replace comma to newline

I am looking just to accommodate my query into one-liner.

I have a below file content where i want to remove all before last colon(:) including itself and then replace comma(,) into newline to get the desired results.

these all comma separated values are linux user ID's

File content:

pa_tools:x:2998:nep08569,nep08623,nep14587,kpc12117,tpa06038,tpa10226,tpa14459,tpa14596,tpa21272,tpa28233,tpa32495,cpf30049,cpf32734,cpf38753,cpf41124,cpf41645,cpf42488,cpf42609,cpf54284,cpf55701,cpf56556,cpf61223,cpf64941,cpf66553,cpf69011,cpf72912,pfc37974,pfc40981,pfc48626,pfc69581,pfc80043,pfc82969,pfc84163,pfc87399,pfc87990,pfc87991,pfc98638,pa_tools_rs

Already tried:

working solution:

1- $  sed -e  's/.*://g' -e  's/\,/\n/g' test_g

2- $ awk -F: '{print $NF}'  test_g| awk 'BEGIN{RS=","}{$1=$1}1'

3- $ cat test_g| tr "," "\n"| tr ":" "\n" | sed '1,3d'

result:

$  sed -e  's/.*://g' -e  's/\,/\n/g' test_g
nep08569
nep08623
nep14587
kpc12117
tpa06038
tpa10226
tpa14459
tpa14596
tpa21272
tpa28233
tpa32495
cpf30049
cpf32734
cpf38753
cpf41124
cpf41645
cpf42488
cpf42609
cpf54284
cpf55701
cpf56556
cpf61223
cpf64941
cpf66553
cpf69011
cpf72912
pfc37974
pfc40981
pfc48626
pfc69581
pfc80043
pfc82969
pfc84163
pfc87399
pfc87990
pfc87991
pfc98638
pa_tools_rs

Is there a better trick, please advise.

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

You may use this solution on any version of awk:

awk -F: '{$0 = $NF; gsub(/,/, "\n")} 1' file

nep08569
nep08623
nep14587
kpc12117
tpa06038
tpa10226
tpa14459
tpa14596
tpa21272
tpa28233
tpa32495
cpf30049
cpf32734
cpf38753
cpf41124
cpf41645
cpf42488
cpf42609
cpf54284
cpf55701
cpf56556
cpf61223
cpf64941
cpf66553
cpf69011
cpf72912
pfc37974
pfc40981
pfc48626
pfc69581
pfc80043
pfc82969
pfc84163
pfc87399
pfc87990
pfc87991
pfc98638
pa_tools_rs

Using gnu-sed it will something similar to your attempted code:

sed 's/.*://; s/,/\n/g' file
over 4 years ago · Santiago Trujillo Denunciar

0

With sed:

sed 's/.*://; s/,/\n/g' file
# needs to be a sed the supports \n
# GNU and recent BSD do support \n but that is a superset
# of POSIX

If your sed does not support \n in replacement, then use a literal escaped new line:

sed 's/.*://; s/,/\
/g' file

Or use tr to replace , with \n:

sed 's/.*://' file | tr ',' '\n'

All three print:

nep08569
nep08623
nep14587
...
pfc87991
pfc98638
pa_tools_rs
over 4 years ago · Santiago Trujillo Denunciar

0

Using sed

$ sed 's/.*:\([^,]*\)\|,/\n\1/g' input_file

nep08569
nep08623
nep14587
kpc12117
tpa06038
tpa10226
tpa14459
tpa14596
tpa21272
tpa28233
tpa32495
cpf30049
cpf32734
cpf38753
cpf41124
cpf41645
cpf42488
cpf42609
cpf54284
cpf55701
cpf56556
cpf61223
cpf64941
cpf66553
cpf69011
cpf72912
pfc37974
pfc40981
pfc48626
pfc69581
pfc80043
pfc82969
pfc84163
pfc87399
pfc87990
pfc87991
pfc98638
pa_tools_rs
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