Anjan1
1
Hi,
I have code like:
Output it is comming as:
Rels: WM2
Rels: WG2
Rels: 5
- pre/prods.pl
Rels: 6
Rels: 7
Rels: 8
Rels: 10
Rels: Int
But i want only "Rels: 5" pattern Just above "- pre/prods.pl".
By creating temp file i am able to do that. But i dont want to use temp file.
Thanks..
So, you want to go back from seeing line 4 to output line 3? Save the last Rel line in one variable and print it when you see the prods.pl line.
Anjan1
3
Can u please tell me how to do it?
how about with awk?
awk '!/-pre\/prods.pl/{x=$0}/- pre\/prods.pl/{print x}' file
Anjan1
5
Actually i want it in perl. Please tell me in perl only.
Split your if-two-patterns into two if-one-patterns, the rel one saves in a variable (what rel am I in), the other prints that variable.
perl -ane 'if($_ =~ /Rels/) {$x = $_};if ($_ = /.*prods\.pl/){print "$x"}' file1
Rels: 5
Anjan1
8
Thanks for the help..it worked...