views:

177

answers:

6

I am searching for "o" then prints all lines with "o". Any suggestion/code I must apply?

data.txt:

j,o,b:
a,b,d:
o,l,e:
f,a,r:
e,x,o:

desired output:

j,o,b:
o,l,e:
e,x,o:
+1  A: 
grep "o" data.txt

Does that help? I don't know Perl, but you can get the same output using the above grep.

artknish
+1  A: 
print if /o/;
Ed Guiness
+3  A: 

If you have grep on your system, then grep o data.txt from the command line should do the trick.

Failing that, you could try Perl:

open IN, 'data.txt';
my @l = <IN>;
close IN;
foreach my $l (@l) {
   $l =~ /o/ and print $l;
}
jbourque
A: 

In Perl:

while (<>) { print if /o/; }

or with grep:

grep 'o' data.txt
Robert Gamble
+8  A: 
grep o data.txt

perl -ne 'print if (/o/);' <data.txt
jj33
A: 

as a very short one-liner:

> perl -pe'$_ x=/o/' filename
Yanick