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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AWK / sed question 1

Status
Not open for further replies.

purek77

Technical User
Oct 9, 2007
7
EU
Hi.

I want to modify my aliases file.
File looks like this:

All.GFX.CityI: All.GFX.CityI@somedomain.com
Manager.GFX.CityI: Manager.GFX.CityI@somedomain.com
Cashier.GFX.CityI: Cashier.GFX.CityI@somedomain.com

All.GFX.CityII: All.GFX.CityII@somedomain.com
Manager.GFX.CityII: Manager.GFX.CityII@somedomain.com
Cashier.GFX.CityII: Cashier.GFX.CityII@somedomain.com

.
.
.

and so on...
We can say, that every block looks like:
All.GFX.<some string>: All.GFX.<some string>@somedomain.com
Manager.GFX.<some string>: Manager.GFX.<some string>@somedomain.com
Cashier.GFX.<some string>: Cashier.GFX.<some string>@somedomain.com

Now, the 'GFX' string has changed for 'SFX' and
I need to change every 3-row part to 6-row part
(I need to preserve old email adressess):

All.GFX.CityI: All.SFX.CityI@somedomain.com
All.SFX.CityI: All.SFX.CityI@somedomain.com
Manager.GFX.CityI: Manager.SFX.CityI@somedomain.com
Manager.SFX.CityI: Manager.SFX.CityI@somedomain.com
Cashier.GFX.CityI: Cashier.SFX.CityI@somedomain.com
Cashier.SFX.CityI: Cashier.SFX.CityI@somedomain.com

Is there a way to do this in automated way ?
 
awk '1;/GFX/{gsub(/GFX/,"SFX");print}' aliasesfile > newfile

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thx PHV. Almost that what I need :)
After this command output looks like this:

All.GFX.CityI: All.GFX.CityI@somedomain.com
All.SFX.CityI: All.SFX.CityI@somedomain.com
Manager.GFX.CityI: Manager.GFX.CityI@somedomain.com
Manager.SFX.CityI: Manager.SFX.CityI@somedomain.com
Cashier.GFX.CityI: Cashier.GFX.CityI@somedomain.com
Cashier.SFX.CityI: Cashier.SFX.CityI@somedomain.com

We only need to change second GFX to SFX in oryginal lines...
 
Oops, misread the post.
awk '/GFX/{gsub(/GFX/,"SFX");print;sub(/SFX/,"GFX")}1' aliasesfile > newfile

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top