[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [TEKNIK] sed-regexp bøvl med at gentage s øg-erstat i en linje



Den torsdag 12.apr kl. 16:26 skrev Kenneth:

Jeg havde en korrupt /etc/group fil i dag, som havde været igennem en margen-justering, dvs. flere korte linjer var rykket sammen på en så de omtrent var 80 tegn i bredden. Således:

daemon:x:2:root,bin,daemon,cyrus,bacula sys:x:3:root,bin,adm
adm:x:4:root,adm,daemon tty:x:5: disk:x:6:root lp:x:7:daemon,lp mem:x:8:


Til det formål forsøgte jeg at få sed til at hjælpe med følgende regexp-besværgelse:
sed -re 's/([a-z0-9]+:x:[0-9]+:[a-z0-9,]*)( )([#a-z0-9]+)/\1\n\3/g'


Til min overraskelse giver det resultatet:

daemon:x:2:root,bin,daemon,cyrus,bacula
sys:x:3:root,bin,adm
adm:x:4:root,adm,daemon
tty:x:5: disk:x:6:root
lp:x:7:daemon,lp mem:x:8:

-altså linje 2 i input bliver til 3 linjer á 1 hhv. 2 grupper i output.
Hvorfor ikke 5 linjer á 1 gruppe, som tilsigtet - og når det nu ikke funker, hvorfor så heller ikke 4 linjer á hhv. 1 og 4 grupper (som jeg ville synes var mere logisk).


Jeg har forstået at /g optionen til s/ funktionen gør at alle tilfælde af søgemønsteret i linjen skulle matches, men er der noget med at man skal nulstille en token-tæller eller noget i den dur?

Der er mig bekendt altid et konstant antal : i en group fil, nemlig 3. Du kunne måske udnytte det, og så afslutte med enten et " " eller $





JonB


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2007-05-01, 02:01 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *