Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

It looks like the pattern you're trying to extract is comprised of exactly seven characters, each of which can be a 1 (one), 0 (zero), or X. However, your sample output shows three results of six characters, so I'm a bit confused.

In any event, if it is seven characters, the pattern you're looking for is /([X01]{7})$/. It also sounds like you only want to skip repeating patterns for groups, not for the entire dataset. For any line which doesn't match that pattern, you want to do what is sometimes known as a "control break" where you reset your data and start again. Thus, if I've understood your requirements correctly, the following simple program shows one way it can be done.

#!/usr/bin/env perl use strict; use warnings; my %seen; while ( my $line = <DATA> ) { if ( $line =~ /([X01]{7})$/ ) { # line matched, so print the pattern if we've not seen it befo +re my $result = $1; next if $seen{$result}++; print "$result\n"; } else { # the line did not match, so clear our "seen" patterns %seen = (); } } __DATA__ Pattern 0 (full_sequential) Time 0: period = 100 Time 0: force_all_pis = XX00X1X Time 200: force_all_pis = XX1X0X1 Time 400: force_all_pis = XXX1XX0 Time 600: force_all_pis = XXX1XX0 Time 800: force_all_pis = XXX1XX0 Time 940: measure_all_pos =1 Pattern 1 (full_sequential) Time 0: period = 100 Time 0: force_all_pis = XX0XX1X Time 200: force_all_pis = XX1XXXX Time 400: force_all_pis = XX0X10X Time 600: force_all_pis = XX1XXXX Time 800: force_all_pis = XX0010X Time 1000: force_all_pis =XX110X1 Time 1140: measure_all_pos =1 Pattern 2 (full_sequential) Time 0: period = 100 Time 0: force_all_pis = XX00X11 Time 200: force_all_pis = XX110X0 Time 340: measure_all_pos =1 Pattern 3 (full_sequential) Time 0: period = 100 Time 0: force_all_pis = XX01X10 Time 200: force_all_pis = XX1X0X1 Time 400: force_all_pis = XX00011 Time 600: force_all_pis = XX1X0X1 Time 740: measure_all_pos =0 Pattern 4 (full_sequential) Time 0: period = 100 Time 0: force_all_pis = XX00X1X Time 200: force_all_pis = XX1XXXX Time 400: force_all_pis = XX010X1 Time 600: force_all_pis = XX10XX0 Time 740: measure_all_pos =0 Pattern 5 (full_sequential) Time 0: period = 100 Time 0: force_all_pis = XXXX0XX Time 200: force_all_pis = XXXX1XX Time 400: force_all_pis = XX0011X Time 600: force_all_pis = XX111X1 Time 740: measure_all_pos =1 Pattern 6 (full_sequential) Time 0: period = 100 Time 0: force_all_pis = XX0X10X Time 200: force_all_pis = XX1XXXX Time 400: force_all_pis = XX0XX1X Time 600: force_all_pis = XX1XXXX Time 800: force_all_pis = XX00X1X Time 1000: force_all_pis =XX110X1 Time 1140: measure_all_pos =0 Pattern 7 (full_sequential) Time 0: period = 100 Time 0: force_all_pis = XXXX1XX Time 200: force_all_pis = XXXX0XX Time 400: force_all_pis = XX0001X Time 600: force_all_pis = XX110X1 Time 740: measure_all_pos =0 Pattern 8 (full_sequential) Time 0: period = 100 Time 0: force_all_pis = XX00X1X Time 200: force_all_pis = XX11XXX Time 400: force_all_pis = XX010X1 Time 600: force_all_pis = XX11XX0 Time 740: measure_all_pos =1 Pattern 9 (full_sequential) Time 0: period = 100 Time 0: force_all_pis = XX00X1X Time 200: force_all_pis = XX11XX0 Time 400: force_all_pis = XX0X0X1 Time 600: force_all_pis = XX1XXXX Time 800: force_all_pis = XXX0XX0 Time 940: measure_all_pos =0

And with that, your output is:

XX1X0X1 XXX1XX0 XX0XX1X XX1XXXX XX0X10X XX0010X XX110X1 XX00X11 XX110X0 XX01X10 XX1X0X1 XX00011 XX00X1X XX1XXXX XX010X1 XX10XX0 XXXX0XX XXXX1XX XX0011X XX111X1 XX0X10X XX1XXXX XX0XX1X XX00X1X XX110X1 XXXX1XX XXXX0XX XX0001X XX110X1 XX00X1X XX11XXX XX010X1 XX11XX0 XX00X1X XX11XX0 XX0X0X1 XX1XXXX XXX0XX0

In reply to Re: How should I Extract data from text file. Pattern I have to extract should not repeated one. by Ovid
in thread How should I Extract data from text file. Pattern I have to extract should not repeated one. by jumdesumit

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-03-29 01:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found