in reply to Re^2: Extracting data from a particular line to end of the file
in thread Extracting data from a particular line to end of the file

The simple implementation of this is like below. Keep a record of whether the "start" has happened yet. And if it has, then print all the lines after that and including that one.

code example and output.. click below..

#!/usr/bin/perl -w use strict; my $seen_once =0; while (<DATA>) { $seen_once =1 if (m/^\*/); print if $seen_once; } =prints: the line "Gain... " IS NOT PRINTED *Check if your claims have been finalized. *Sign up for alerts about your claim activity. *Print a temporary ID card. *View up to 18 months of claim payment details. *Much, much more! In addition you, your spouse and children can: *Search for Doctors and Hospitals in your area. *Begin a program to stop smoking or lose weight. *Learn more about a specific disease or condition". =cut __DATA__ "Gain immediate access and... *Check if your claims have been finalized. *Sign up for alerts about your claim activity. *Print a temporary ID card. *View up to 18 months of claim payment details. *Much, much more! In addition you, your spouse and children can: *Search for Doctors and Hospitals in your area. *Begin a program to stop smoking or lose weight. *Learn more about a specific disease or condition".
More specific version of your code:
open (my $file1,"<$dir/seq.results") or die "cannot open "$dir/seq.res +ults"; open (my $file2,">$dir/seq.out") or die "cannot open $dir/seq.out" for + write"; my $started =0; while (<$file1>) { $started =1 if (m/^\*/); #first line starting with * is seen print $file2 "$_" if $started; }
Note: '*' has special meaning within a regex and it has to be "escaped" to get the literal value of '*'.

Yes, there are ways of coding this in a more brief way. But do not confuse brevity with execution efficiency and certainly not clarity.

Oh, in a very simple program like this (6 lines), there is no need to explicitly close the file handles ($file1 and $file2). The OS will do that for you when the program exits. In longer programs there can be good reasons to do that.

Replies are listed 'Best First'.
Re^4: Extracting data from a particular line to end of the file
by manne (Novice) on Dec 21, 2010 at 18:18 UTC
    Thankyou marshall, That was really helpful...