Tips For Awk
  1. # prepend and append some text on each line of a text file:
     awk '{print "prefix "$1" postfix"}' input.txt > /tmp/output.txt 
    
  2. # replace the value of the second column in file1.dat by zero if it is strictly less than 0.1 (cfr., the gnuplot manual):
     awk '{print $1,($2<0.1) ? 0.0 : $2}' file1.da 
    
  3. # multiply the numeric value of the second column in file1.dat by five if the value of the first column is in the range of [1,3] (cfr., the gnuplot manual):
     awk '{print $1,($1<=3 && $1>=1)? $2*5 : $2}' file1.dat 
    

----

Tips For MyHowTos
  1. # text processing:
    1. # convert characters from lower to upper case:
       fortune | tr [:upper:] [:lower:] 
      
    2. # finding out how many times a particular item, in this case a dot, occurs on a text line
       for a in `cat /tmp/file.txt`; do
        nof=$[`echo $a|sed s/'\.'/'\n'/g|wc -l` -1]
        echo  a . occurs $nof times in $a
       done
      
    3. # unescaping escaped text/html/javascript/... found in a file $LOGFILE:
       cat $LOGFILE|sed s/+/' '/g|sed s/%0D%0A/" -- "/g|sed s/%20/" "/g|sed s/%21/'!'/g|\
      sed s/%22/'"'/g|sed s/%23/'\#'/g|sed s/%24/"$"/g|sed s/%25/"%"/g|sed s/%26/"\&"/g|sed s/%27/"'"/g|\
      sed s/%28/'('/g|sed s/%29/')'/g|sed s/%2A/'*'/g|sed s/%2B/'+'/g|sed s/%2C/','/g|sed s/%2D/'-'/g|\
      sed s/%2E/'.'/g|sed s/%2F/'\/'/g|sed s/%3A/':'/g|sed s/%3B/';'/g|sed s/%3C/'<'/g|sed s/%3D/'='/g|\
      sed s/%3E/'>'/g|sed s/%3F/'?'/g|sed s/%40/'@'/g|sed s/%5B/'['/g|sed s/%5C/'\\'/g|sed s/%5D/']'/g|\
      sed s/%5E/'^'/g|sed s/%5F/'_'/g|sed s/%60/'`'/g|sed s/%7B/'{'/g|sed s/%7C/'|'/g|sed s/%7D/'}'/g|\
      sed s/%7E/'~'/g|sed s/%D3/'<'/g 
      
    4. # a very nice overview of commonly used text processing commands can be found at http://www.tldp.org/LDP/abs/html/textproc.html
    5. # remove all blank lines from a file:
       grep -v '^$' input.txt > output.txt 
      
    6. # count the number of newlines, words and bytes in a text file:
       wc input.txt 
      
    7. # reverse all the lines in a file:
       rev file.txt 
      
  2. # searching for specific patterns using grep and regular expressions (mostly copied from http://www.robelle.com/library/smugbook/regexpr.html):
    1. # the theory:
       ^ (Caret)        =    match expression at the start of a line, as in ^A.
       $ (Question)     =    match expression at the end of a line, as in A$.
       \ (Back Slash)   =    turn off the special meaning of the next character, as in \^.
       [ ] (Brackets)   =    match any one of the enclosed characters, as in [aeiou].
                             Use Hyphen "-" for a range, as in [0-9].
       [^ ]             =    match any one character except those enclosed in [ ], as in [^0-9].
       . (Period)       =    match a single character of any value, except end of line.
       * (Asterisk)     =    match zero or more of the preceding character or expression.
       \{x,y\}          =    match x to y occurrences of the preceding.
       \{x\}            =    match exactly x occurrences of the preceding.
       \{x,\}           =    match x or more occurrences of the preceding. 
      
    2. # examples:
       cat -v -e -t dump                           # show non-printing characters too
       grep BOB tmpfile                        # search 'tmpfile' for 'BOB' anywhere in a line
       grep -i -w blkptr *                     # case insensitive search all files in the current directory for the word blkptr
       grep run[- ]time *.txt                  # find 'run time' or 'run-time' in all txt files
       grep smug files                         # search files for lines with 'smug'
       grep '^smug' files                      # 'smug' at the start of a line
       grep 'smug$' files                      # 'smug' at the end of a line
       grep '^smug$' files                     # lines containing only 'smug'
       grep '\^s' files                        # lines starting with '^s', "\" escapes the ^
       grep '[Ss]mug' files                    # search for 'Smug' or 'smug'
       grep 'B[oO][bB]' files                  # search for BOB, Bob, BOb or BoB 
       grep '^$' files                         # search for blank lines
       grep '[0-9][0-9]' file                  # search for pairs of numeric digits
       grep '^From: ' /var/spool/mail/$USER    # list your mail
       grep '[a-zA-Z]'                         # any line with at least one letter
       grep '[^a-zA-Z0-9]                      # anything not a letter or number
       grep '[0-9]\{3\}-[0-9]\{4\}'            # 999-9999, like phone numbers
       grep '^.$'                              # lines with exactly one character
       grep '"smug"'                           # 'smug' within double quotes
       grep '"*smug"*'                         # 'smug', with or without quotes
       grep '^\.'                              # any line that starts with a Period "."
       grep '^\.[a-z][a-z]'                    # line start with "." and 2 lc letters 
      
  3. # file processing:
    1. # count the number of times a particular character (in the example a comma) occurs in some file:
       cat file.txt | tr -c -d ',' | wc -c 
      
    2. # character set translator -- translates character sets from one encoding to another (utf-8, ascii, iso 8859-[123456789], unicode, msdos,...):
       tcs 
      
    3. # make a hexdump or do the reverse:
       xxd file > file.hex
       xxd -r file.hex > file.bis 
      
    4. # dump a file byte per byte using octet, decimal, hex or binary notation:
       od -j 2 -t x1 file > file.hex 
      
    5. # replace all spaces in all relevant file names by underscores:
       find . -name \*' '\* -exec rename s/' '/_/g "{}" \; 
      
    6. # strip the path from a filename, or the last part of an absolute path:
       basename extendedFilename; dirname extendedFilename 
      
    7. # find all files that are between 100 and 50 days old:
       find . -mtime +50 -mtime -100 -daystart 
      
  4. # process processing:
    1. # redirect stderr to stdout:
       buggyProg 2>&1 
      
    2. # redirect stdout to stderr:
       buggyProg 1>&2 
      
    3. # redirect both stderr and stdout to a file:
       buggyProg &> file 
      

----

Tips To Use Cvs
  1. # checkout of a cvs module from a cvs server with respect to a particular date:
     cvs -z3 -d :pserver:cvs@cvs.server.org:/pub/cvsroot checkout -D "month dd yyyy" module 
    

----

Tips To Use Diff And Patch
  1. # the following command produces (given two source trees ~/original/sources and ~/updated/sources) an overview of the differences between these two trees:
     cd ~/original/sources
     tar -xzvf ~/whatever.tgz
     cd ~
     diff -ruN original/sources updated/sources > how.to.patch.original.sources
    
  2. # the following command produces, given the original source tree and the differences between the original and updated sources, updated sources:
     cd ~/current/sources
     tar -xzvf ~/whatever.tgz
     patch -p2 < how.to.patch.original.sources
    

----

Setting Up An Encrypted Filesystem
  1. # http://loop-aes.sourceforge.net/loop-AES.README
  2. # Encryption HOWTO
  3. # Encrypted Root Filesystem HOWTO
  4. # Cryptoloop HOWTO
  5. # Setting up the Cryptographic FileSystem (cfs):
    1. # setting the thing up:
      1. # install the cfs package:
         sudo apt-get install cfs 
        
      2. # create /etc/exports if it does not yet exist to avoid cfsd's complaints:
         sudo touch /etc/exports 
        
      3. # start the cfs daemon:
         sudo /etc/init.d/cfsd restart 
        
    2. # using the stuff:
      1. # prepare the creation of an encrypted directory called "~/encrDir":
         cmkdir ~/encrDir 
        
        # the cmkdir command prompts for a strong passphrase (of at least 16 characters)
      2. # make this directory available to the user with that password:
         cattach ~/encrDir decrypted 
        
        # the cattach command prompts for the passphrase that was used to create the directory ~/encrDir # once completed, the directory /crypt/decrypted becomes available wherein one can edit all files in plaintext
      3. # once you finish editing the decrypted data, this directory should be unmounted:
         cdetach decrypted 
        
        # note that the content of the directory ~encrDir is at all times encrypted. The plaintext is only available to the user who presented the correct passphrase

----

Tips For Mysql
  1. # setting the server root password:
     mysql -uroot mysql
     mysql>UPDATE user SET Password=PASSWORD('mysqlrootpassword') WHERE user='root';
     mysql>FLUSH PRIVILEGES;
     mysql>quit
    
  2. # initial setting up of diogenes:
     mysql -uroot -p"mysqlrootpassword"
     mysql> use diogenes;
     mysql> insert into diogenes_auth set username="root",password=MD5(""),perms="admin";
     mysql> quit
    

----

Tips For Perl
  1. # look for a specific pattern in standard input (binary or text files) and print the pattern's byte-offset:
    #!/usr/bin/perl
    open(P,"-");
    $a=join("",<P>);
    while($a =~ m/pattern/gs){
            print join(/:/,@-)."\n";
            }
    close(P); 
    
  2. # find all common lines in two files (cfr., http://perlmonks.thepen.com/36725.html):
     perl -ne 'print if ($seen{$_} .= @ARGV) =~ /10$/' fileA fileB >output 
    

----

Tips For Sed
  1. # have sed fetch all lines from a text file starting from the sixth line:
     sed -n '6,$p' file.txt 
    
  2. # append line i to line i+1 if line i+1 starts with $PATTERN:
     sed ':a;N;$!ba;s/\n$PATTERN/$PATTERN/g' file.txt 
    
  3. # a list of handy one-liners for the unix stream editor sed can be found at http://www.student.northpark.edu/pemente/sed/sed1line.txt

----