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

finding and replaceing text

Status
Not open for further replies.

dominga

Programmer
May 26, 2003
2
US
i need to change an entry in file
the file has 26 unique entried (unique on city name)
first i need to find the city name
then go backwards to the 26th char and change one measly number!
example:
111.11.111|1234|222.22.222|4321|DALLAS_PORT|PRIMARY|333.33.333|PORT|DALLAS_PORT|SECONDARY

what i need to do is find dallas, and change the last 2 in the ip address (222.22.222) to a 3. i have tried awk sed, cut etc. but i seem to keep changing more than the one city i need to change (there are other city names with the same ip and i dont want to touch them)

thanks!)
 
Your example is a bit confusing, e.g. why are there a instances of "DALLAS" on the line? But the folowing (untested) awk program might get you started.

/DALAS/{print substr($0,1,25) "3" substr($0,27)



CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
this file has 26 sites and their ips and port numbers thats why there is dallas but there is also like atlanta that has the same ip but different port numbers.

111.11.111|1234|222.22.222|4321|DALLAS_PORT|PRIMARY|333.33.333|PORT|DALLAS_PORT|SECONDARY

111.11.111|1234|222.22.222|5555|ATLANTA_PORT|PRIMARY|333.33.333|PORT|ATALANTA_PORT|SECONDARY

thats why i have to find dallas first and then search for the ip that comes before the city and change the last digit of the ip (in order to point primary server to the secondary server) does that make more sense?
 
Did my solution do what you want? (If you correct my typo "DALAS" to "DALLAS and add traling } , that is)

Or maybe you need

BEGIN {FS=OFS="|"}
/DALLAS/{$2=substr($2,1,length($2)-1) "3"; print}


CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top