Showing posts with label Scripting. Show all posts
Showing posts with label Scripting. Show all posts

Wednesday, August 17, 2011

List lines in file A but not in file B

I found this interesting scripts' page: http://tkhanson.net/misc/ and I think that I got an alternative to the anb script:


#!/usr/bin/perl

use strict;
use warnings;

sub usage {
        print "$0: filea fileb\n";
        exit -1;
}

usage unless scalar @ARGV == 2;

my $a = shift @ARGV;
my $b = shift @ARGV;

open A, "<$a" or die "can't open $a: $!\n";
open B, "<$b" or die "can't open $b: $!\n";

my %bl;
$bl{$_}++ for (<B>);

for (<A>) {print "$_" unless $bl{$_}};
__END__
Or using map for the last lines:
my %bl = map {$_ => 1 } (<B>);
map {print "$_" unless $bl{$_}} (<A>);




TIMTOWTDI

Tuesday, July 26, 2011

Using Windows Script for sending keys to an application

Open the calculator and show the About message for 3 seconds:


Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run("calc")
WScript.Sleep(100)
WshShell.AppActivate("Calculator")
WScript.Sleep(100)
WshShell.SendKeys("%H")
WScript.Sleep(500)
WshShell.SendKeys("{DOWN}")
WScript.Sleep(100)
WshShell.SendKeys("~")
WScript.Sleep(3000)
WshShell.SendKeys("{ESC}")

Close the Calculator:


Set WshShell = WScript.CreateObject("WScript.Shell")
Result = WshShell.AppActivate("Calculator")
WScript.Sleep(100)
If Result = True Then
WshShell.SendKeys "%{F4}"
End If

References:
http://technet.microsoft.com/en-us/library/ee156592.aspx
http://msdn.microsoft.com/en-us/library/8c6yea83(v=vs.85).aspx