0

I am trying to replace version number (like 00.00.00-00) in a file with actual version number in shell.

For this I use the following command:

sed -i 's/[0-9]*\.+[0-9]*\.+[0-9]*\-+[0-9]*/MyNewVersion/g' file.txt

Example of the file.txt:

Some text Bla Bla Bla-00.00.00-00.x86_SomeOtherInterestingThings

Unfortunately it does not give me desired result. Any advice?

1
  • Remove all +. Commented Sep 20, 2017 at 8:36

2 Answers 2

1

First of all, you would need -r flag in order to mark the pattern as a regular expression. Next, you would need to move the quantifier + next to the number ranges, so I believe you should be using this command:

sed -i -r 's/[0-9]+\.[0-9]+\.[0-9]+-[0-9]+/MyNewVersion/g' file.txt
Sign up to request clarification or add additional context in comments.

2 Comments

Well, even without -r that would be parsed as a regex, -r will make it be parsed as a POSIX ERE pattern (where + quantifier does not need escaping, in BRE POSIX, in GNU sed, + can be used if escaped). No need to escape -, BTW.
Removed backslash before -
0

based on the example input/pattern, this line should help:

sed 's/[-0-9.]\+\([.]x86_\)/-NEW\1/'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.