This works as expected:
INPUT FILE src.txt:
ffmpeg -i uno.3gp
ffmpeg -i dos.3gp
ffmpeg -i tres.3gp
COMMAND:
sed 's/-i .*\./XXX/' <src.txt
RESULT AS EXPECTED:
ffmpeg XXX3gp
ffmpeg XXX3gp
ffmpeg XXX3gp
Then why don’t these work as expected:
COMMAND:
sed 's/-i (.*)\./XXX/' <src.txt
EXPECTED:
ffmpeg XXX3gp
ffmpeg XXX3gp
ffmpeg XXX3gp
ACTUAL RESULT:
ffmpeg -i uno.3gp
ffmpeg -i dos.3gp
ffmpeg -i tres.3gp
COMMAND:
sed 's/-i (.*)\.3gp/\1.mp3/' <src.txt
EXPECTED:
ffmpeg uno.mp3
ffmpeg dos.mp3
ffmpeg tres.mp3
ACTUAL RESULT
sed: -e expression #1, char 18: invalid reference \1 on `s' command's RHS
The parenthesis don’t seem to work for grouping, but all the tutorials and examples I’ve found around seem to assume they should…
In Classic
sed(not GNUsednecessarily), the grouping commands use\(and\)(and the counts use\{and\}) rather than unescaped.Thus, you should try:
Or, if you’ve got GNU
sed, add-ror--regexp-extendedto ‘use extended regular expressions in the script’ (quoting fromsed --help).