2

I would like to replace each version old number in a file with a new one. For example 1.12.5 with 1.13.

My solution so far is this command: sed -i '' -e "s/1.12.5/1.13/g" file.txt

For now I have the problem that this command also replaces the numbers, if they appear separately in a line, e.g. blabla 1.12.5blablabf1b12b5blabla -> blabla 1.13blablabf1.13blabla However it should return blabla 1.13blablabf1b12b5blabla.

Thanks in advance.

ByteGo
  • 21
  • 2
  • Does this answer your question? [What special characters must be escaped in regular expressions?](https://stackoverflow.com/questions/399078/what-special-characters-must-be-escaped-in-regular-expressions) – Wiktor Stribiżew Jan 07 '21 at 13:42

2 Answers2

2

Generic solution: Could you please try following, written and tested with shown samples only.

sed -E 's/[0-9]+\.[0-9]+\.[0-9]+/1.13/' Input_file

Specific solution: Above is generic one, in case you want to go for specific version then you need to escape . to make it as a literal character to be treated.

sed 's/1\.12\.5/1.13/' Input_file

Please use -i option with sed to save output into Input_file itself.

RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
2

Dot is special in sed regexes. It means "any character". Backslash it for literal meaning:

sed -i '' -e 's/1\.12\.5/1.13/g'
choroba
  • 231,213
  • 25
  • 204
  • 289