help with perl and awk ...

M

martin

Hi, I am trying to traverse a directory tree and to see if there are
any symbolic links present. if that is true, then I would like to print
a message to that effect.

I would like to use "ls -lR" for recursive search (as opposed to perl's
find) and then pipe the resutls into awk and search for "-lr" or "-l-"
occurences at the beginning of the ls lisitng provided
i.e. all symbolic link lines.

I am not an expert in any of these, so any help appreciated

This is the beginning
my $command = "ls -lR | awk /^-l[-r]/ | wc"

and then something like system($command).

Is there a better approach to this.

Not sure if I am on the right track. Thanks.

Martin
 
D

DJ Stunks

martin said:
[Dear comp.lang.perl.misc] I am trying to traverse a directory tree and to see if
there are any symbolic links present. if that is true, then I would like to print
a message to that effect.

I would like to use "ls -lR" for recursive search (as opposed to perl's
find) and then pipe the resutls into awk and search for "-lr" or "-l-"
occurences at the beginning of the ls lisitng provided
i.e. all symbolic link lines.

I am not an expert in any of these, so any help appreciated

This is the beginning
my $command = "ls -lR | awk /^-l[-r]/ | wc"

and then something like system($command).

Is there a better approach to this.

Not sure if I am on the right track. Thanks.

You're definitely NOT on the right track.

The good news is that the first step is the easiest - become an
"expert" on finding the right group to ask.

Call me crazy, but the rule of thumb I usually use is to NOT ask a
bunch of experts in one field how to do a particular task while
specifically stating that whatever happens I definitely to not want the
solution to use that field.

Some might think that a "better approach."

Thanks for the laugh though.

-jp
 
R

Rahul

martin said:
Hi, I am trying to traverse a directory tree and to see if there are
any symbolic links present. if that is true, then I would like to print
a message to that effect.

I would like to use "ls -lR" for recursive search (as opposed to perl's
find) and then pipe the resutls into awk and search for "-lr" or "-l-"
occurences at the beginning of the ls lisitng provided
i.e. all symbolic link lines.

Not sure why you would not prefer a tested perl module like File::Find
(if it is a Perl program you want to write)
I am not an expert in any of these, so any help appreciated

This is the beginning
my $command = "ls -lR | awk /^-l[-r]/ | wc"

The awk portion in the above command is incorrect
$ man awk

grep would be a better choice.
$ man grep

To count the number of links in current dir and its sub-dirs
$ ls -lR | grep -c '^l'
and then something like system($command).

Is there a better approach to this.

To list all the links in a dir and its sub-directories, try this on the
command line
$ find /dir/to/search -type l -name \*
 
R

Rahul

martin said:
Hi, I am trying to traverse a directory tree and to see if there are
any symbolic links present. if that is true, then I would like to print
a message to that effect.

I would like to use "ls -lR" for recursive search (as opposed to perl's
find) and then pipe the resutls into awk and search for "-lr" or "-l-"
occurences at the beginning of the ls lisitng provided
i.e. all symbolic link lines.

Not sure why you would not prefer a tested perl module like File::Find
(if it is a Perl program you want to write)
I am not an expert in any of these, so any help appreciated

This is the beginning
my $command = "ls -lR | awk /^-l[-r]/ | wc"

The awk portion in the above command is incorrect
$ man awk

grep would be a better choice.
$ man grep

To count the number of links in current dir and its sub-dirs
$ ls -lR | grep -c '^l'
and then something like system($command).

Is there a better approach to this.

To list all the links in a dir and its sub-directories, try this on the
command line
$ find /dir/to/search -type l -name \*
 

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

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top