J
J Krugman
I've rtfm'd this to death, but I still don't get it. If someone
can explain it to me (as opposed to tell me something like "man
perlfrotz"), I'd be very grateful.
The immediate problem that serves as the context of the question
is this: find all the files below /path/to/subdir (this is Linux)
that contain either of the strings "foo bar baz" or "quux frobozz",
and do this *from the command line* (i.e. I'm looking for a one-liner
here, not a longwinded affair using File::Find, etc.).
I tried
% perl -e 'print "$ARGV\n" if grep /(foo bar baz|quux frobozz)/, <>' `find /path/to/subdir -type f`
which failed to generate any output, even though I *know* that
there are files under /path/to/subdir that contain strings "foo
bar baz" and/or "quux frobozz".
Even if it had worked, the last alternative is not good, because
it can easily fail through choking the shell with an excessively
long arguments list. There has to be a better way.
At any rate, I also tried
% perl -e 'for (@ARGV) { print "$ARGV\n" if grep /(foo bar baz|quux frobozz)/, <> }' `find /path/to/subdir -type f`
which also failed. In fact, even
% perl -e 'for (@ARGV) { print "$ARGV\n" }' `find /path/to/subdir -type f`
failed: it generated a whole bunch of empty lines. Clearly I have
*no clue* of what's going on. What exactly is the relationship
between $ARGV and <>? Is it possible to write a simple one-liner
that cycles through all the lines of *each* of the files in named
in @ARGV and prints the name of the file if at least one of its
lines meets a condition?
Any help would be much appreciated.
jill
can explain it to me (as opposed to tell me something like "man
perlfrotz"), I'd be very grateful.
The immediate problem that serves as the context of the question
is this: find all the files below /path/to/subdir (this is Linux)
that contain either of the strings "foo bar baz" or "quux frobozz",
and do this *from the command line* (i.e. I'm looking for a one-liner
here, not a longwinded affair using File::Find, etc.).
I tried
% perl -e 'print "$ARGV\n" if grep /(foo bar baz|quux frobozz)/, <>' `find /path/to/subdir -type f`
which failed to generate any output, even though I *know* that
there are files under /path/to/subdir that contain strings "foo
bar baz" and/or "quux frobozz".
Even if it had worked, the last alternative is not good, because
it can easily fail through choking the shell with an excessively
long arguments list. There has to be a better way.
At any rate, I also tried
% perl -e 'for (@ARGV) { print "$ARGV\n" if grep /(foo bar baz|quux frobozz)/, <> }' `find /path/to/subdir -type f`
which also failed. In fact, even
% perl -e 'for (@ARGV) { print "$ARGV\n" }' `find /path/to/subdir -type f`
failed: it generated a whole bunch of empty lines. Clearly I have
*no clue* of what's going on. What exactly is the relationship
between $ARGV and <>? Is it possible to write a simple one-liner
that cycles through all the lines of *each* of the files in named
in @ARGV and prints the name of the file if at least one of its
lines meets a condition?
Any help would be much appreciated.
jill