Skip to content

Instantly share code, notes, and snippets.

@mshock
Created May 15, 2012 16:47
Show Gist options
  • Save mshock/2703173 to your computer and use it in GitHub Desktop.
Save mshock/2703173 to your computer and use it in GitHub Desktop.
filter and sort by value file containing rows of key = value
#! /usr/bin/perl
# filter rows to ones containing search_value
# sort the rows by search_value
# usage: filter_sort.pl file search_value
$search_value = $ARGV[1];
open (F, '<', $ARGV[0]);
@lines;
for(<F>) {
if (m/$search_value\s*=\s*(\d+)/) {
#print "matched $1 $_\n";
push @lines, [$1,$_];
}
}
close F;
@sorted = sort {$a->[0] <=> $b->[0]} @lines;
open(O, '>', 'sorted.txt');
foreach $line (@sorted) {
#print @{$line}[1];
print O @{$line}[1];
}
close O;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment