Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Search file for certain lines

by mtmcc (Hermit)
on Sep 23, 2013 at 09:48 UTC ( #1055257=note: print w/replies, xml ) Need Help??


in reply to Search file for certain lines

I'm not entirely sure what you're trying to do. Surely, all lines in your file will be between two lines beginning with h, aside from those before the first line beginning with h, and after the last line beginning with h?

It might make it easier to understand the problem if you give some sample data, and the result you expect to get. Have a look through this: How do I post a question effectively?

Finally, based on your question, my best guess would be something like this:

#!/usr/bin/perl use strict; use warnings; my $file = $ARGV[0]; my $check = 0; my @line; while (<DATA>) { @line = split('', $_); $check += 1 if $line[0] eq 'h'; if ($check%2 == 1) { if (($line[0] eq 'j') || ($line[0] eq 'E') || ($line[0 +] eq 'G')) { print STDOUT "$_"; } } } __DATA__ aaaaa 1 bbbbb 2 hhhhh 3 fffff 4 rrrrr 5 lllll 6 jjjjj 7 HHHHH 8 EEEEE 9 GGGGG 10 hhhhh 11 jjjjj 12 EEEEE 13 GGGGG 14

I hope that helps.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1055257]
help
Chatterbox?
[holli]: you should visit the link i posted and answer my question
[stonecolddevin]: good afternoon all
[holli]: if you know what's good for you
[holli]: hahaha
[stonecolddevin]: hey holli, long time no chat
[holli]: g'day sir
[holli]: can you believe they only did nine episodes this season? GoT that is
[holli]: here's the link for you again devin: https://hastebin. com/uhifarelir.rb

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2017-09-26 21:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (297 votes). Check out past polls.

    Notices?