Perl Command line for this problem

Discussion in 'Perl Misc' started by tweetiebirds@gmail.com, Mar 21, 2005.

  1. Guest

    Hi,

    I am trying to use Perl command line for a bunch of sys admin tasks.

    I would like to do this:
    ------------------------

    Read output from a perl -V command and grep for lines containing words
    starting with /usr or many spaces followed by /usr

    then search these lines (each line will be a directory starting with
    /usr or spaces and then /usr) for a filename (dogs.dat)

    How can I do this efficiently with perl command line (perl -i -pi etc
    ).

    Thanks,
    T
     
    , Mar 21, 2005
    #1
    1. Advertising

  2. wrote:
    >
    > I am trying to use Perl command line for a bunch of sys admin tasks.
    >
    > I would like to do this:
    > ------------------------
    >
    > Read output from a perl -V command and grep for lines containing words
    > starting with /usr or many spaces followed by /usr
    >
    > then search these lines (each line will be a directory starting with
    > /usr or spaces and then /usr) for a filename (dogs.dat)
    >
    > How can I do this efficiently with perl command line (perl -i -pi etc
    > ).


    This should get you started:

    perl -MConfig -le'print "$_ = $Config{$_}" for grep $Config{$_} =~
    /^\s*\/usr/, keys %Config'


    John
    --
    use Perl;
    program
    fulfillment
     
    John W. Krahn, Mar 22, 2005
    #2
    1. Advertising

  3. <> wrote:

    > I am trying to use Perl command line for a bunch of sys admin tasks.
    >
    > I would like to do this:
    > ------------------------
    >
    > Read output from a perl -V command and grep for lines containing words
    > starting with /usr or many spaces followed by /usr
    > then search these lines (each line will be a directory starting with
    > /usr or spaces and then /usr)



    Not if we follow your specification above they won't be.

    libpth=/usr/local/lib /lib /usr/lib

    has "words starting with /usr", so that line should match.


    > for a filename (dogs.dat)
    >
    > How can I do this efficiently



    I thought you wanted a one-liner?

    Why is efficiency a criterion?


    > with perl command line (perl -i -pi etc
    > ).



    perl -V | perl -ne 'next unless m#^\s*/usr#; s#.*/##; print'


    But I smell an XY-problem.

    I doubt you need perl -V at all:

    perl -le 's#.*/##, print for grep m#^\s*/usr#, @INC'


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Mar 22, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lucas Cowald
    Replies:
    4
    Views:
    1,102
    Tohid
    Oct 23, 2003
  2. Dib Urim
    Replies:
    4
    Views:
    206
    Michele Dondi
    Dec 3, 2003
  3. lucy
    Replies:
    7
    Views:
    192
    Joe Smith
    Sep 3, 2004
  4. Replies:
    2
    Views:
    165
    Tad McClellan
    Mar 26, 2005
  5. Ting Wang
    Replies:
    3
    Views:
    203
    Paul Lalli
    Dec 13, 2005
Loading...

Share This Page