vikas
vikas

Reputation: 89

Select multiple lines from a file and save it to a new file using perl

i have a file from which i have to grep multiple lines between two specific string and save it to a new file as it is ..

The file is as below:

module abc (
abc,
efg,
..
..
 );
core M1 sj
corem m2
apple 
......

the starting string is module and last string is ");" . The desired output is as below:

module abc (
abc,
efg,
..
..
 );

below is the script which i had tried :

open(my $fh, "<", "test.v")
or die "Failed to open file: $!\n";
my $original = <$fh>;
close($fh);

open(INFILE, ">", "result.v")
my $abc = $original =~ /module .*\)\;/ ;   //selecting string from module to ");" 
print INFILE $abc;
close(INFILE);

Kindly help me with a perl script .

Thank You

Upvotes: 0

Views: 81

Answers (1)

ikegami
ikegami

Reputation: 386396

perl -ne'print if /^module/ .. /^\s*\);/'

Specifying file to process to Perl one-liner

Upvotes: 2

Related Questions