[mdlug] GNU sed weirdness
Jeff Hanson
jhansonxi at gmail.com
Mon Jan 25 01:33:44 EST 2010
On Sun, Jan 24, 2010 at 11:40 PM, John Wiersba <jrw32982 at yahoo.com> wrote:
> Jeff,
>
> I mostly agree with Aaron (quoted below). But just because you can write
> unreadable perl doesn't mean that you have to. I would suggest using perl
> to rewrite this as perl's towering strength is text manipulation. In
> general, perl subsumes and unifies both sed and awk functionality.
>
> The following shell script does what I interpret you want based on your
> original post. Since you already have filelist.txt, you can skip the
> creation and removal of it and just use the perl command. This script
> produces the following output:
>
> "c:\Program Files\7-Zip\7z.exe" a -mx=7 -ms=on -wD:\ "D:\archive"
> "D:\data\20100123.*"
>
> -- John Wiersba
>
> cat <<EOF >filelist.txt
> D:\data\20100123.idx
> D:\data\20100123.dat
> EOF
>
> perl -e '
> for (@ARGV) {
> ($var, $val) = split /=/, $_, 2;
> $opt{$var} = $val;
> }
> $_ = <STDIN>;
> chomp;
> s/\.[^.]+\z/.*/;
> print qq{"$opt{compress_exe}" $opt{compress_opts} "$opt{target_dir}"
> "$_"\n};
> exit 0;
>
> ' compress_exe='c:\Program Files\7-Zip\7z.exe' \
> compress_ext='7z' \
> compress_opts='a -mx=7 -ms=on -wD:\' \
> target_dir='D:\archive' \
> < filelist.txt
>
> rm filelist.txt
>
>
Interesting. Thanks for the help.
More information about the mdlug
mailing list