ramblinpeck has asked for the wisdom of the Perl Monks concerning the following question:

I know how to do this with a script, but trying to figure out how to do it from the command line. Have a large file that I want to parse various IDs out of, don't care about anything else. They are in the format script_id'number_here';
I thought
perl -pe "if(m/script_id\'(.*)\'/){print $1;}" my_file.log
would do it, but its printing out the whole line. Thanks for any help.

Replies are listed 'Best First'.
Re: More Command Line Regex
by tirwhan (Abbot) on Apr 07, 2006 at 14:11 UTC

    perldoc perlrun, the -p option always prints the whole line, either use -n instead or do something like this:

    perl -pe 's/script_id\'(.*)\'/$1/' my_file.log

    All dogma is stupid.
Re: More Command Line Regex
by borisz (Canon) on Apr 07, 2006 at 13:59 UTC
    untested: perl -nle "/script_id\'(.*)\'/ and print $1" my_file.log
    Boris