Perl Command line for this problem

T

tweetiebirds

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
 
J

John W. Krahn

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
 
T

Tad McClellan

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'
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top