Reputation: 3
I have many lines
Hi i need to work for
This place
Which adds me
More value in this
wolrd
Where i can explore my technical skills
i am searching for the words adds me =~ /adds/
If the match found i have to print the whole line "Which adds me"
How to do this in perl
Upvotes: 0
Views: 177
Reputation: 188
I have wondered if one can solve the problem using the option -p. Finally I have found this oneliner
perl -pe 'goto LINE unless /adds/;' filename
Upvotes: 0
Reputation: 101
if its in file
open(FH,'filename");
while(<FH>){
if($_=~/adds/){
print $_;
}
}
Upvotes: 0
Reputation: 10278
With perl
command:
perl -ne '/adds/ && print $_' file
output:
Which adds me
in script.pl:
while (<>) {
print if (/adds/);
}
then invoke script:
perl script.pl file
Upvotes: 1
Reputation: 2944
while (<STDIN>) {
if($_ =~ m/adds me/) { ##this worked for me
print $_;}
}
Upvotes: 1