MAHALO

posted by Arkham on May 25th, 2009

My brand-new really-cheap dark-purple ukulele!

photo-15

Tags: , , ,

Awk by examples

posted by Arkham on April 14th, 2009

auk

AWK is a language for processing files of text. A file is treated as a sequence of records, and by default each line is a record. Each line is broken up into a sequence of fields, so we can think of the first word in a line as the first field, the second word as the second field, and so on. An AWK program is of a sequence of pattern-action statements. AWK reads the input a line at a time. A line is scanned for each pattern in the program, and for each pattern that matches, the associated action is executed.

Basics

  1. Print /etc/mtab (awk reads a line at time and prints it) :

    awk '{ print }' /etc/mtab
  2. Print /etc/mtab ($0 denotes the whole line) :

    awk '{ print $0 }' /etc/mtab
  3. List mounted filesystems ($1 denotes the first element of the line) :

    awk '{ print $1 }' /etc/mtab
  4. List groups (-F chooses the Field Separator) :

    awk -F":" '{ print $1 }' /etc/group
  5. List groups and id (awk concatenates print() arguments) :

    awk -F":" '{ print $1 " " $3 }' /etc/group
  6. List groups and id (Nicer format) :

    awk -F":" '{ print "group: " $1 "\tid: " $3 }' /etc/group
  7. Launching external awk scripts :

    # first.awk
    BEGIN {
        FS=":"
    }
    { print $1 }
    awk -f first.awk /etc/mtab
  8. List IPv4 addressess :

    ifconfig | awk '/inet / { print $2 }'
  9. List processes run by root :

    # psroot.awk
    $1 == "root" { 
        printf("ROOT: "); 
        for (i=11; i<=NF; i++) 
            printf("%s ", $i);
        printf("\n")
    }
    ps au | awk -f psroot.awk
  10. Print X warnings :

    awk '$1 ~ /(WW)/ { print }' /var/log/Xorg.0.log
  11. Print a file removing comments :

    awk '! /^#/ { print }' /etc/fstab
  12. Print number of files/directories :

    ls -lA |  awk 'BEGIN{ x=0 } { x=x+1 } END{ print x-1 }'
  13. Awk as calculator :

    echo | awk '{ print ((2*5^2-1)%7) }'
  14. Count empty lines :

    # blanklines.awk
    BEGIN { x=0 } 
    /^$/  { x=x+1 } 
    END   { print "I found " x " blank lines :)" }
    awk -f blanklines.awk /etc/profile
  15. Use regexp as FS (note the difference though) :

    echo '   a   b c  d '| awk -F"[ \t\n]+" '{ print $2 }'
    echo '   a   b c  d '| awk -F" " '{ print $2 }'
  16. Understand NR and NF :

    # nrnf.awk
    BEGIN { x=0 } 
          { print "Words on line " NR ": " NF ; x+=NF } 
    END   { print "Total lines: " NR ; print "Total words: " x }
    awk -f nrnf.awk nrnf.awk

Tags: , , , ,

Latex disadvantages

posted by Arkham on March 9th, 2009

latexandsubversion

LATEX also has some disadvantages, and I guess it’s a bit difficult for me to find any sensible ones, though I am sure other people can tell you hundreds ;-)

  • LATEX does not work well for people who have sold their souls . . .
  • Although some parameters can be adjusted within a predefined document layout, the design of a whole new layout is difficult and takes a lot of time.
  • It is very hard to write unstructured and disorganized documents.
  • Your hamster might, despite some encouraging first steps, never be able to fully grasp the concept of Logical Markup.

From the “The Not So Short Introduction to LATEX

Tags: ,

Learning to touch type

posted by Arkham on October 3rd, 2008

I finally got so bored of my typos to start learning to touch type.
For now it’s like trying a new way to walk, when you are used to do it in a different way for like 20 years. Pretty painful.

P.S. This post was touch typed.

Tags: