
Alekto
Novice
Jan 9, 2010, 11:33 AM
Post #1 of 3
(261 views)
|
|
Write line to file if match
|
Can't Post
|
|
Hi, I was wondering how I can write a whole line from one file to another (emty)file, only if that line contains a special word. This is what I got this far:
#!/usr/bin/perl open (IN, "<in.txt") or die ("can't open file: in.txt"); open (OUT, ">>out.txt"); while ($line = <OUT>){ $pattern =~ m/special_word/; if ($line == $pattern){ print NUMBER "$line\n"; } } close (SLOW); close (NUMBER); As you can see I have been trying to use regex, but I am not shure if this is the way to go... This is how the input(in.txt) file is suppost to look like:
blablablablabla..................................... blablablablabla..................................... blablablablabla...........special word........ blablablablabla..................................... blablablablabla..................................... blablablablabla...........special word........ blablablablabla...........special word........ blablablablabla..................................... blablablablabla..................................... blablablablabla...........special word........ blablablablabla..................................... Tnx! X Alekto
|