trouble backreferencing with sed
Hi all,
I'm running Fedora8 on an AMD x64 have some iterating text in a flat file I'd like to change, but keep the iteration. For example, parts of my file say "Ge1:1 then some text, Ge1:2 then some more text...Ge1:22...." I'd like to replace "Ge1:n" with "<sub>n</sub>" - basically, I'm formatting something in HTML and want to put the number after the colon into superscript and lose the "Ge1:" I'm reading a sed tutorial (see link below) and came up with the following: sed s/Ge1\:\([0-9]*\)/\<sub\>\1\<\\/sub\>/ a.txt > b.txt But it doesn't replace anything. When I run: sed s/Ge1\:[0-9]*\ /\<sub\>\<\\/sub\>/ a.txt > b.txt it works fine, but I lose "n" Does anyone know why the "\1" isn't recognizing the "\([0-9]*\)" ? http://www.grymoire.com/Unix/Sed.html Thanks, William |
You haven't quoted the sed substitution, and the shell is eating the backslashes. Place quotes around your expression. Also, you can use a different substitution field delimiter to reduce the backslashes. Finally, don't backslash characters that don't need to be escaped.
Here's a solution: Code:
sed 's-Ge1:\([0-9]*\)-<sub>\1<\/sub>-' |
Thanks!
Thank you!
|
All times are GMT -5. The time now is 09:27 AM. |