I am trying to shorten the string in linux and retaining the extension in linux using sed but my command is erroring out with "sed: -e expression #1, char 21: unknown option to `s'"
The string I take is "15400_AP705_OUT_03112016_0513_001.DAT" and the output I am looking for is 15400_AP705.DAT
The command I am using is
echo 15400_AP705_OUT_03112016_0513_001.DAT | sed -r "s//(.{11}).*(\..*)$/$1$2/"
Regards, Srinath
There one slash too many in the
sed
command, you should use single-quotes (not double-quotes) to avoid shell substitutions and use\N
for back-references (i.e. not$1
but\1
):Note that the
-r
option tosed
is not supported on all platforms. On Mac OSX systems, use-E
instead.