Skip to content

Instantly share code, notes, and snippets.

@zengargoyle
Created October 17, 2010 19:50
Show Gist options
  • Save zengargoyle/631196 to your computer and use it in GitHub Desktop.
Save zengargoyle/631196 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl -CSDAL
#
# Usage: PROGNAME big_list.txt small_list.txt > output.txt
# -CSDAL for unicode.
use strict;
use warnings;
# should maybe have this
use locale;
# Read the big/small list file names
my $bigfile = shift @ARGV;
my $smallfile = shift @ARGV;
# Read the small list file, map to UPPER CASE, remove line ending
my @small = do { local @ARGV = $smallfile; <> };
@small = map { uc $_ } @small;
chomp @small;
my %small;
$small{$_} = undef for @small;
# Read through the big list file
@ARGV = $bigfile;
while (<>) {
chomp; # Get rid of line ending
print; # print without any number following and no line ending
my $big = uc $_; # make it UPPER CASE
#if (grep { $big eq $_ } @small) { # if it is in small list
if (exists $small{$big}) { # if it is in small list
print " 2"; # add a " 2" to the end.
}
print "$/"; # print the line ending
}
@zengargoyle
Copy link
Author

$ cat one 
One
Two
Three
Four

$ cat two 
three
one

$ ./program.pl one two
One 2
Two
Three 2
Four

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment