alinhe os números do identificador de segurança horizontalmente

0

Eu tenho esses identificadores de segurança (SIDs)

SID_1
S-1-2-12-347289564783285475
SID_2
S-1-2-12-312478290434839212
S-1-2-12-312748912347723432
S-1-2-12-123475184123489632
SID_3
SID_4
S-1-2-12-384721849326143123
S-1-2-12-324624783246712332
SID_5
SID_6

e preciso alinhá-los horizontalmente para poder alimentá-los com um algoritmo que aceita apenas os IDs dessa forma:

SID_1:S-1-2-12-347289564783285475
SID_2:S-1-2-12-312478290434839212:S-1-2-12-312748912347723432:S-1-2-12-123475184123489632
SID_3
SID_4:S-1-2-12-384721849326143123:S-1-2-12-324624783246712332
SID_5
SID_6

Como isso pode ser feito?

    
por Jeff Schaller 09.10.2018 / 22:04

2 respostas

1

com awk :

awk '/^S-/{s=s":"$1;next}s{print s}{s=$0}END{print s}' file

SID_1:S-1-2-12-347289564783285475
SID_2:S-1-2-12-312478290434839212:S-1-2-12-312748912347723432:S-1-2-12-123475184123489632
SID_3
SID_4:S-1-2-12-384721849326143123:S-1-2-12-324624783246712332
SID_5
SID_6
    
por 09.10.2018 / 22:08
0

usando sed

sed -i ':a;N;$!ba;s/\nS-/:S-/g' file
SID_1:S-1-2-12-347289564783285475
SID_2:S-1-2-12-312478290434839212:S-1-2-12-312748912347723432:S-1-2-12-123475184123489632
SID_3
SID_4:S-1-2-12-384721849326143123:S-1-2-12-324624783246712332
SID_5
SID_6
    
por 09.10.2018 / 22:11