[mdlug] GNU sed weirdness

Jeff Hanson jhansonxi at gmail.com
Sun Jan 24 02:12:31 EST 2010


On Sun, Jan 24, 2010 at 1:39 AM, Raymond McLaughlin
<driveray at ameritech.net> wrote:
> I'm still looking at your command string. I'm not sure if or how word
> wrap is messing with it.
>
> sed -n 's/\(.*\)\\\(.*\)\.idx/'"\"$compress_exe\" $compress_opts
> \"$target_dir\\"'\2'".$compress_ext"'\" \"\1\\2.*\"/p' $1
>
>
> The first and second double quotes are in the construct: "\"
>
> Are you quoting the backslash, or backslash escaping the second double
> quote? if the latter, where is the "mate" to the first double quote?

...idx/'"\"$compress_exe = replacement text starts with terminating
single quote followed by a double quoted section to allow variable
expansion.  The first item added to the output is an embedded double
quote as Windows needs the 7-zip path quoted because of spaces in the
path (i.e. "Program Files").  Then the path is added followed by
another embedded double quote, space, the 7-zip options and another
space.

\"$target_dir\\" = escaped double quote at the start of the target
(.7z) archive path, the path itself from the variable, followed by an
embedded (escaped) backslash.

'\2' = single quoted back-reference (#2 is the filename w/o
extension), with a closing single quote.  This is where sed seems to
get confused between the escaped backslash and the back reference.  I
can't remember all the quote combinations I tried and what the errors
were but this should have worked.

".$compress_ext" = period and 7-zip file extension (.7z).

The rest just reproduces the source file path and filename.  The
effect is to replace the original extension with an * so 7-Zip grabs
all the files with the same names and any extension.



More information about the mdlug mailing list