Archive for June, 2007

Special Bash Variables

Posted in Uncategorized on June 25, 2007 by aghoras

$* - This denotes all the parameters passed to the script
at the time of its execution. Which includes $1, $2
and so on.
$0 - Name of the shell script being executed.
$# - Number of arguments specified in the command line.
$? - Exit status of the last command.

Tab size in VI

Posted in Uncategorized on June 22, 2007 by aghoras

To set the tab size in vi

:set sts=4

To enable autoindent

:set ai

Exporting and Importing Data into Postgres

Posted in Programming on June 22, 2007 by aghoras

To export a postgres database

 pg_dump mydb > db.sql

To reload such a script into a (freshly created) database named newdb:

$ psql -d newdb -f db.sql

VI substitution

Posted in Uncategorized on June 22, 2007 by aghoras
#substitution
:%s/fred/joe/igc            : general substitute command
:%s//joe/igc                : Substitute what you last searched for *N*
:%s/~/sue/igc               : Substitute your last replacement string for *N*

If statements in SQL

Posted in Programming on June 22, 2007 by aghoras

To have a conditional statement in a SELECT statement, use CASE WHEN…THEN….ELSE.

create view logbook as
        select  "Date",
                "N Number",
                "From","To",
                "Number of Instrument Approaches",
                "Number of Night Landings",
                "Total Flight Duration" - "Night" as "Day",
                "Night",
                "Simulator",
                "Simulated Instrument",
                "Actual Instrument",
                 case when "IsCrossCountry" = true  then "Total Flight Duration"  else 0.0 end as "Cross Country"
         from flights;

Mnemonic for Order of #

Posted in Uncategorized on June 20, 2007 by aghoras

Father Charles Goes Down and Ends Battle

Reversed:

Battle Ends and Down Goes Charles’ Father

A simple file IO program in Perl

Posted in Programming on June 20, 2007 by aghoras

This program searches the instructions.txt file line by line to and print the lines immediately after the ones matching the Patter /Read.*RegAddr:\ 0×3/.

#!/usr/bin/perl
open INSTR_FILE, "< Instructions.txt" or die "Cannot open instruciton file $!";
print "## Register 3n";
while ($line = <INSTR_FILE>){
        if ($line =~ /Read.*RegAddr: 0x3/){
                $line = <INSTR_FILE>;
                @fields = split /t/,$line;
                print $fields[2],"n";
        }
}
close INSTR_FILE;

Converting Tabs to spaces

Posted in Uncategorized on June 13, 2007 by aghoras

To convert tabs to spaces, use “expand” on unix. Use “unexpand” to convert spaces into tabs.