0

Hey so I want to replace a regex pattern with nothing, I've tried multiple sed routes but none seem to be working, i.e

sed -i 's/\.\d{1,3}\b$//'

Example of input,

Hello.123
Hello.123.90

expected output would be,

Hello
Hello.123
  • So what are you trying to match? You've shown us a regex that does not do what you want, but you haven't explained what you need. Are you trying to remove the last . followed by 1 to 3 numbers from each line? What if a line is foo.1234? Should we leave that unchanged? – terdon Dec 5 '19 at 0:49
  • Yes I want to remove the last dot followed by 1 to 3 numbers from each line. – Valkyrie Dec 5 '19 at 0:52
  • OK, so what happens with foo.1234? Nothing? Do we just print the line? – terdon Dec 5 '19 at 0:53
1

Maybe yo can try something like this:

sed -i -E 's/\.[0-9]{1,3}$//' file
| improve this answer | |
  • thank you for your help – Valkyrie Dec 5 '19 at 1:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.