Home > Software design >  bash script replace only match and start special IP address?
bash script replace only match and start special IP address?

Time:09-16

Can you please help me bash script? i need use only start and match iP address. for example

Y8.78.94 488752   X1.188 36582   62.111.101.260 #S 
Y8.62.111 5789544 X1.132 5364789 8.8.4.4 #S  

but when i use this command

> sed -i 's/62.111./Z./g' test.txt

But the result it change all like as:

Y8.78.94 488752   X1.188 36582   Z.101.260 #S 
Y8.Z. 5789544 X1.132 5364789 8.8.4.4 #S 

Y8.Z. it is wrong we should be not changed it

CodePudding user response:

In a regular expression, . matches any character. So 62.111. matches 62.111 followed by space at the beginning.

You should match the . literally by escaping it.

sed -i 's/62\.111\./Z./g' test.txt
  • Related