Hello,
I have a pattern like "XXXXXX XXXXXX" which i need to make search in a input file and Replace the matched pattern to a another pattern.
This is the code i tried ..
#!/usr/bin/perl
print "Enter a File name :";
chomp ($file = <STDIN>);
print "\n Searching file :";
if (system ("ls $file")==0)
{
print "File Found\n";
$lines = `wc -l $file`;
@personal = split(/ /, $lines);
$lines = @personal[0];
print "Total number of lines in the file = $lines \n";
print "Enter the pattern to search :";
chomp ($pattern = <STDIN>);
print "\n";
# to search the no of words (pattern search)
$abc=`grep $pattern $file | wc -l`;
print "Total number of results found $abc \n";
print "here are the results ...\n";
system("grep $pattern $file");
}
else{
print "File not Found\n";
}
This code works where i input a pattern without spaces like "MAX",
But when i give a Pattern like this "MAX XAM", the script errors out.
I tried to put "/s" also, its erroring out.
How can i search a pattern which is embeded with a space between two words.
Can any one please help.
Thanks
Rahul