in reply to Re: System command stdout
in thread System command stdout

Wot im trying to do in perl is  tar tf file | grep gz | grep -v sig This should leave just the file.gz filename to pass to stdout Then pass this as a variable to  tar xOf file variable | grep.... I've managed to do this by passing the stdout to a tmp file and reading this in using cat, but I want to do this without using a tmp file.

Replies are listed 'Best First'.
Re^3: System command stdout
by tuxz0r (Pilgrim) on Nov 27, 2007 at 18:05 UTC
    On the command line you could do,
    tar -cvf newarchive.tar `tar -tf archive.tar | grep "gz" | grep -v "si +g"`
    However, in your perl program, you could simply backtick to capture the ".gz" filename you want (using Perl's grep), and then pass that to system as the argument to the tar -cvf command. e.g.,
    my @gzfiles = grep { m/gz/ && ! m/sig/ } `tar -tf archive.tar` my @args = ( "tar","-cvf","newarchive.tar", @gzfiles ); system(@args) == 0 or die "Can't archive files: $!\n@gzfiles";

    ---
    echo S 1 [ Y V U | perl -ane 'print reverse map { $_ = chr(ord($_)-1) } @F;'
    Warning: Any code posted by tuxz0r is untested, unless otherwise stated, and is used at your own risk.