Hello jumdesumit,

Another alternative way (most likely not so efficient) using IO::All, but just for fun.

#!/usr/bin/perl use strict; use IO::All; use warnings; use Data::Dumper; my $output = io('out.txt'); my @lines = io('in.txt')->chomp->slurp; my %hash; while (defined(my $str = shift @lines)) { if (index($str, 'XX') != -1) { my @array = split /=/, $str; $array[1] =~ s/^\s+|\s+$//g; $hash{$array[1]} = $array[0]; } } my @final = keys %hash; print Dumper \@final; while (defined(my $strOut = shift @final)) { $output->write ($strOut . "\n"); } __END__ $ perl test.pl $VAR1 = [ 'XX00011', 'XX111X1', 'XX0001X', 'XX0010X', 'XX00X1X', 'XX0011X', 'XXXX0XX', 'XX01X10', 'XXX1XX0', 'XX010X1', 'XX11XX0', 'XX110X1', 'XX0X0X1', 'XXXX1XX', 'XX0X10X', 'XX1XXXX', 'XX1X0X1', 'XX00X11', 'XX0XX1X', 'XX110X0', 'XXX0XX0', 'XX11XXX', 'XX10XX0' ]; $ cat out.txt XX00011 XX111X1 XX0001X XX0010X XX00X1X XX0011X XXXX0XX XX01X10 XXX1XX0 XX010X1 XX11XX0 XX110X1 XX0X0X1 XXXX1XX XX0X10X XX1XXXX XX1X0X1 XX00X11 XX0XX1X XX110X0 XXX0XX0 XX11XXX XX10XX0

BR / Thanos

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: How should I Extract data from text file. Pattern I have to extract should not repeated one. by thanos1983
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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.