vendredi 6 mars 2015

how to modify matches to a regular expression with sed or another tool?


I need to substitute one regular expression for another with sed or another command line tool: ,4 --->,4) ,15 ---> ,15)


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 fine for 1st line above but not 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:



,15 ---> ,15)


Any advice would be greatly appreciated. Thank you.



Aucun commentaire:

Enregistrer un commentaire