Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to take out some lines !!

Status
Not open for further replies.

rao12

IS-IT--Management
Jan 10, 2001
9
0
0
US
i have a file with contents like

<<< file1: abcd.c
>>> file2: abcd.cx
--------[after 12]-----|-----------[inserted 67-80]------
---------[deleted 67-89]---|---------[after 56]----------
<<< file1: def.c

how do i select only lines that come in between >>> and
<<<

ie.,

--------[after 12]-----|-----------[inserted 67-80]------
---------[deleted 67-89]---|---------[after 56]----------

and from this i would like to take out the

12 67-80
67-89 56


i appreciate the prompt from goboating and i thank him for the same.and it gave me some idea but the expression

($buffer =~ />>>(.*?)<<</gs) is not working please help me at your earliest
what will happen when $chunk = $1; I am new to perl may be the doubt is silly but i would like to get it clarified...as nothing was printed on STDOUT
when i gave print &quot; $chunk&quot;;

=============================================================================
solution by goboating
==================================================

I have not run this, but it should be pretty close. Inside the inner most 'while', do what ever you like with the numbers.

open(IPF,&quot;<inputFile&quot;) or die &quot;Failed to open inputFile, $!\n&quot;;
while (<IPF>) { $buffer .= $_; }
close IPF;

# while matching stuff between >>> and <<<
while ($buffer =~ />>>(.*?)<<</gs)
{
# catch matched strings in $chunk
$chunk = $1;
{
while ($chunk =~ /\[\w+ (.*?)\]/gs) { $numbers = $1; }
}
}

'hope this helps


 
Try this code to get the selected lines from the file:

open(FILE,&quot;YourFile&quot;);
while (<FILE>) {
if (/>>>/ .. /<<</) { #match your line markers
push(@lines,$_);
}
}

foreach $i (@lines) {
print &quot;$s&quot;;
}

All thats left is to strip out the text not wanted to get the numbers - let me know if you want me to give you ideas on that aswell.

Matt - matt@mousematt.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top