Randomly selecting lines by line number 
Author Message
 Randomly selecting lines by line number

I can use the line of code below (which I lifted from the Perl book)
in a perl script to print a number of lines after a designated matching
line in a file.

  ..
  print if (/REGEX/ ? ($count=LINES) : (--$count > 0));
  ..

Does anyone know if its possible to select a line by its line number instead
of a regular expression like sed or ed?

Chris Brown



Mon, 26 Dec 1994 17:32:34 GMT  
 Randomly selecting lines by line number

:I can use the line of code below (which I lifted from the Perl book)
:in a perl script to print a number of lines after a designated matching
:line in a file.
:
:  ..
:  print if (/REGEX/ ? ($count=LINES) : (--$count > 0));

That said

    $count = 'LINES';

which is odd.

:Does anyone know if its possible to select a line by its line number instead
:of a regular expression like sed or ed?

Consult the $. variable.

    if ($. == 7) { }

or implicitly:

    if (7..12) { }

--tom

--

    Real programmers can write assembly code in any language.   :-)  



Mon, 26 Dec 1994 22:02:48 GMT  
 Randomly selecting lines by line number

Quote:

>I can use the line of code below (which I lifted from the Perl book)
>in a perl script to print a number of lines after a designated matching
>line in a file.
>  ..
>  print if (/REGEX/ ? ($count=LINES) : (--$count > 0));
>  ..
>Does anyone know if its possible to select a line by its line number instead
>of a regular expression like sed or ed?

There are lots of ways.  Here are a couple:

  print if 5..8;        # print lines 5, 6, 7 and 8.
  print if $. >= 5 && $. <= 8;

Michael.



Mon, 26 Dec 1994 21:04:34 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Randomly selecting lines of text?

2. displaying lines with a specific number of lines on each page

3. Searching a WORD 6 DOC by line line number

4. Perl line numbers vs Apache error_log reported numbers?

5. Regex & grep to select lines, help plse

6. Best way in perl to select matching lines

7. perl: copy selected line from one file to another

8. Selecting a random line from a text file

9. selecting lines for single spacing

10. perl: copy selected line from one file to another

11. SELECT(rbits,wbits,ebits,timeout) adds blank line to file

12. Extracting selected lines from a file

 

 
Powered by phpBB® Forum Software