I'm having a problem using the sed substitution option that executes a command in the replacement pattern. I believe the option is an extensions to GNU sed but I haven't been able to find any documentation on it. Anyone know of any?
My problem is that I can't extract the matching text properly when using the execute replacement option. I'm using GNU sed 4.2 on Mac OSX 10.7.4
echo "12345678\r" | sed 's/.*/echo "&);"/e'
Result: );345678
Desired Result: 12345678);
I've tried using different regex matches, such as \d+, but that just seems to break the ability to use the /e substitution option. And I've tried using an explicit capture group such as \1 instead of & but that also seems to break the /e option.
Update:
My example was perhaps oversimplified what I'm ultimately trying to do is take a text file with each line holding a unique value and pass that to sed and use the uuidgen command (in the same manner as a previous question I posted). The new problem I've got is because I'm now running the command on a Mac the \r is not being stripped from the matched string.
The full command I want to execute is:
sed 's/.*/echo "blah blah `uuidgen`,&):"/e' file.txt
Update 2:
In my Mac terminal I don't need to use echo -e to get \r interpreted as a line feed and in fact according to "man echo" there is no -e option. It does make life difficult moving between all the terminal environments :(.
Thanks to kev I was able to come up with a solution that worked on Mac.
sed 's/\r//; s/.*/ echo "blah blah (`uuidgen`,&);"/e' file.txt