[SATLUG] sed and Regular expression question

Frank Huddleston fhuddles at gmail.com
Thu Mar 14 14:20:40 CDT 2013


    I'd like to know how to use sed to replace part of a matched string 
but leave part of it as it was before. That is, if sed can even do this. 
Here's my example: I've got a lot of music files: the Diabelli 
Variations by Beethoven. Each one has something like 
"Variation_29GAllegro-moderato" in it. I'd like to put a dash after that 
"G", but just replacing "G" with "G-"
is error-prone and just sloppy. So I think my regular expression match 
would be something like /Variation_[0-9]+G/.
Feel free to jump in and correct that.
But whatever it is: how do I "save" and put that number in the 
replacement string?
Yes, I know that Perl and Awk can do this. I just want to know: can sed 
do it, and if so, how?

Thanks for any help you can provide.

Frank Huddleston

More information about the SATLUG mailing list