I am fresher in writing perl scripts,so i am asking this as question or support on this, below is the code
start pattern1
line1
Matching pattern can be here
line2
Matching Pattern can be here
line3
line4
...
end pattern1
.
start pattern1
line1
line2
start pattern1
start pattern1
line1
Matching pattern can be here
line2
start pattern1
so from perl i need to grep the lines between start pattern1 ... end pattern1, for this i am using awk command to grep
$cmd = q(awk '/start pattern1/,end pattern1 /' x.file );
$n1 = system($cmd);
For this output works fine,Below is the output,
start pattern1
line1
**Matching pattern can be here**
line2
**Matching Pattern can be here**
...
end pattern1
But in the files i have 1000 of lines like this, so i need to grep those lines which have Matching pattern. i.e i need to grep only those starting pattern lines to ending pattern lines has matching pattern
For this i tried
$cmd = q(awk '/start pattern1/,end pattern1 /' x.file | grep '$n2\|line4');
$n1 = system($cmd);
But when i use the above command i don't see any output Here $n2 contains some pattern which is grepped from another file.
if i use direct matched patternin place of $n2 it works fine, why cant i use $n2 here?
Note:i am using this in perl script
From the Awk command i get all the lines between start pattern1...end pattern1,But i have 1000 of such prints, so i need the bunch of the lines of start pattern1 to end pattern1 of thos which get matched with the matching pattern
The expected output when i do is,
start pattern1
line1
Matching pattern can be here
line2
Matching Pattern can be here
line3
line4
...
end pattern1
start pattern1
line1
Matching pattern can be here
line2
start pattern1