Created
May 15, 2012 16:47
-
-
Save mshock/2703173 to your computer and use it in GitHub Desktop.
filter and sort by value file containing rows of key = value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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