Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

229
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!