Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

separate stanzas using empty line 1

Status
Not open for further replies.

w5000

Technical User
Nov 24, 2010
223
PL
hello

input file contains many user stanzas in password file but some stanzas are not as expected separated by empty line (like in example below guest4,5,6 stanzas are not separated).
how to easily correct it in whole file to be able "grep -p ^username:" in this file?

I tested:
sed '/^.*:$/{x;p;x;}'
and
sed '/^.*:/{x;p;x;}'

I hope ":" will never happen in any type of password = and lastupdate =, flags = attributes.
can it be prevented extra in above command(s)?

Code:
guest3:
        password = s.gtrwrwr545.
        lastupdate = 1142355052
        flags =

guest4:
        password = z.GwvrwrrwjA
        lastupdate = 1142355057
        flags =
guest5:
        password = 
guest6:
        password = F0wrwrwrwrF.
        lastupdate = 1250607014

guest7:
        password = yPorwrehfghI
        lastupdate = 1250607020
        flags =
 
What about this ?
awk 'NR>1 && nf && /:$/{printf "\n"}{nf=NF;print}' /path/to/input

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
A more secure way:
awk 'NR>1 && nf && /^[^ \t]*:$/{printf "\n"}{nf=NF;print}' /path/to/input

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
w5000, just to know, did you try my suggestion ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top