Thursday, November 24, 2022

Read lines from a text file and print those lines based on condition using perl

 use strict;

use warnings;

#disabling output buffering

$|=1;


sub main{

#my @files=('./a.txt','./b.txt','./c.txt',);

my $file='./a.txt';

open(INPUT,$file) or die("Input file $file not found.\n");

while(my $line=<INPUT>)

{

if($line=~/abc/)

{


print $line;

}

}

close(INPUT);

}

main();


No comments:

Post a Comment