I need to manipulate text that's in a file.
I need to append a right parenthesis –
) – after every number
that's preceded by a comma –
, – e.g.,
I am struggling to find the proper way to do this with
sed. I tried the following, which works for 1 digit but can't seem to be extended to 2 digits (so it's fine for first line above but not the second):
sudo sed 's/,\([0-9]\)/,\1)/g' filename
So then I tried the following for 2 digits:
sudo sed 's/,\([0-9]([0-9]?\)/,\1)/g' filename
This didn't do anything - the file remained unchanged, though I did not receive an error message. What is the proper way to search for one required digit and a second optional digit and then move them both into the replacement text? I still need to accomplish this:
Any advice would be greatly appreciated.