#1
|
|||
|
|||
Regexp Guru wanted
I have a text file consisting of a single column of player names.
I want this to turn into a series of rows, none of which is over 100 characters in length, with the player names comma deliminated and all duplicate player names removed. Or for a high level view, if you can think of another way to do it: I want to take the export of all fish names from PT and make it into a bunch of strings that I can copy and paste into the Party Search function. [img]/images/graemlins/smile.gif[/img] |
#2
|
|||
|
|||
Re: Regexp Guru wanted
Perl script with 5-6 lines, or just open it up in Excel, and copy/paste using transpose, and save it as CSV
|
#3
|
|||
|
|||
Re: Regexp Guru wanted
[ QUOTE ]
Perl script with 5-6 lines, or just open it up in Excel, and copy/paste using transpose, and save it as CSV [/ QUOTE ] Using excel is how I have been doing it. But as the datamining continues the fish list is growing rather long. There is essentially no way around copying and pasting the finished search strings into Party manually, so I wanted to cut down on the rest of the work as much as possible. |
#4
|
|||
|
|||
Re: Regexp Guru wanted
Perl:
1. Rip through file, parsing out player names into an associative array 2. Join the array with commas |
#6
|
|||
|
|||
Re: Regexp Guru wanted
[ QUOTE ]
Perl: 1. Rip through file, parsing out player names into an associative array 2. Join the array with commas [/ QUOTE ] Assuming you have Perl, save this as list_from_row.pl <font class="small">Code:</font><hr /><pre> #!/usr/bin/perl # usage: list_from_row.pl [[filename]...] my $MAX_LENGTH = 100; my $OUTPUT_FILE = "fishFrySearch.txt"; my %fish; open OUT, ">$OUTPUT_FILE" || die "Could not open output file $OUTPUT_FILE for writing.\n"; foreach my $file (@ARGV) { my $count=0; if (! -f $file) { print "$file is not a file.\n"; } else { open IN, $file || die "Could not open $file"; while (my $name = <IN> { $count++; $name =~ s/^\s*//; $name =~ s/\s*$//; $fish{$name}++ if ($name); } } print "Processed $count lines from $file.\n", scalar(keys %fish)," unique names total.\n"; } my $line=''; foreach my $name (sort keys %fish) { if (length($line) + length($name) >= $MAX_LENGTH) { printLine($line); } else { $line .= $name . ','; } } printLine($line); sub printLine() { my $line = shift @_; $line =~ s/,$//; print OUT $line, "\n"; } </pre><hr /> |
#7
|
|||
|
|||
Re: Regexp Guru wanted
Awesome! Thank you so much.
|
|
|