Tuesday, July 19, 2011

find:bad option find: path-list predicate-list error

This error happens when the wildcard character in your find command expands.
This mainly happens when you run inside a script rather than from a command prompt.
For example inside the perl program you have something like:


@files=`find . -name *C* `;

When you run this program it will through this error:
find:bad option
find:path-list predicate list

Solution to it is enclose the wildcards within single quote or double quotes like this
to prevent the error:

@files=`find . -name '*'C'*' `;
(or)
@files=`find . -name "*C*"`;

Finding the occurence of word in line perl

Perl Program:

#!/usr/bin/perl
$line = "The most hello great hello great important";
@array=split(/hello/,$line);
$count=scalar(@array);
$count = $count -1 ;
print "The no of occurences of hello in line is $count";

OUTPUT:

G:\perl_programs>perl perl_no_of_words.pl
The no of occurences of hello in line is 2
G:\perl_programs>


Analysis:
Here is split function is used to split line based on the word hello.And the no of split words will be 1 more than the occurence of the word.So we need to subtract 1.