patric has asked for the wisdom of the Perl Monks concerning the following question:
please help :(input file: mylist_1 sublist_153 sublist_87 sublist_876 sublist_78 mylist_6 sublist_8 mylist_2 sublist_12 sublist_34 sublist_09 mylist_3 sublist_87 sublist_09 mylist_7 sublist_8 sublist_9 mylist_9 sublist_56 in the above example, line 2 is a substring of line5. since line5 is l +onger than line2, only only line5 is taken for results. another examp +le is line4 is a substring of line3, since line3 is longer, i take on +ly that for results. another example: apple orange cake juice apple fruits car van bus jeep sumo hat people van car in the above example, apple in found in 2 lines, but i keep only the l +ine which has many elements compared the other. car is found in last +line and 3rd line. but i take only the 3rd line as hit because it has + many elements compared to last line. so my result would be: apple orange cake juice car van bus jeep sumo hat my program: #!/usr/bin/perl open(FH,"input_file.txt") or die "can not open input file"; while($line=<FH>){ @collect=split(/\s+/,$line); push(@aoa,join("#",@collect)); } my %h; for(@aoa){ push(@uaoa,$_ if !$h{join $;, @$_}++; } foreach(@uaoa){ print "$_\n"; } the desired output for this problem: mylist_1 sublist_153 sublist_87 sublist_876 sublist_78 mylist_7 sublist_8 sublist_9 mylist_2 sublist_12 sublist_34 sublist_09 mylist_9 sublist_56
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to find the unique lines in a file?
by ELISHEVA (Prior) on Apr 22, 2009 at 08:00 UTC | |
by patric (Acolyte) on Apr 22, 2009 at 09:38 UTC | |
by ELISHEVA (Prior) on Apr 22, 2009 at 10:02 UTC | |
|
Re: how to find the unique lines in a file?
by Anonymous Monk on Apr 22, 2009 at 13:15 UTC | |
by patric (Acolyte) on Apr 22, 2009 at 13:34 UTC |