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!

modify multiple stanzas 1

Status
Not open for further replies.

w5000

Technical User
Nov 24, 2010
223
PL
hello,

the input file contains:

Code:
aaaaaaaaaaaaaaa
bbbbbbbbbbbbbbb
ccccccccccccccc
some header
sssssssssssssss

cfg:
     test=a
     nc=3
     mode=vvv
     nl=7

cfg:
     test=b
     nc=1
     mode=vvv
     nl=5

There are many "cfg:" stanzas in the file. What I need it to replace each nl's value in each cfg: stanza with corresponding nc's in that stanza so finally get output from example above:

Code:
aaaaaaaaaaaaaaa
bbbbbbbbbbbbbbb
ccccccccccccccc
some header
sssssssssssssss

cfg:
     test=a
     nc=3
     mode=vvv
     nl=3

cfg:
     test=b
     nc=1
     mode=vvv
     nl=1


best regards.
 
A starting point:
Code:
awk '/nl=/{print c;next}/nc=/{c=$0;sub(/nc=/,"nl=",c)}1' /path/to/input

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
incredible, it does the job!
thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top