Recent Notes

Displaying keyword search results 1 - 7
Created by Dr. Xi on March 28, 2011 11:11:33    Last update: March 28, 2011 11:13:21
grep is a versatile command with many variations (grep, egrep, fgrep, then various implementations). It uses a regula expression (regex) pattern to filter input. But then there are basic and extended flavors of regex - leading to even more confusion. And, beware that there are lots of bad examples of regex in the wild... There are two critical questions to ask when you use grep: which grep implementation are you using? what is the flavor of the regex? Here are some examples for gnu grep v2.7: # Find all numbers (no decimal point), basic regex... Use the -o flag to show only the matching part instead of the whole matching line: grep -o -E '\b[0-9]{2}\b' The good thing about the gnu grep is that it...
Created by Dr. Xi on February 28, 2011 12:29:19    Last update: February 28, 2011 12:30:40
The Unix shell passes these parameters to the shell script: Variable Meaning $* A single string representing all command line arguments separated by $IFS (internal field separator, usually a space) $@ A sequence of strings representing the command line arguments. $1,$2...$n $1 is the first argument, $2 is the second argument, and so on... $0 The name of the script itself. $# The number of arguments. Example shell script ( sharg.sh ): #!/bin/sh echo $# arguments passed to $0: $@ ... Output for ./sharg.sh "a b c d" : 1 arguments passed to ./sharg.sh: a b c d here ... Output for ./sharg.sh a "b c" d : 3 arguments passed to ./sharg.sh: a b c d here ...
Created by Dr. Xi on January 31, 2011 16:24:31    Last update: January 31, 2011 16:24:58
Perl file test operators are unary operators that takes one argument, which can be a file name, a filehandle, or dirhandle. If the argument is omitted, it tests $_ , except for -t , which tests STDIN. Syntax: -X FILEHANDLE -X EXPR -X DIRHANDLE -X where X is: Operator Meaning -r File is readable by effective uid/gid. -w File is writable by effective uid/gid. -x File is executable by effective uid/gid. -o File is owned by effective uid. -R File is readable by real uid/gid. -W File is writable by real uid/gid. -X File is executable by real uid/gid. -O File is owned by real uid. -e File exists. -z File has zero size (is empty). -s File has nonzero size (returns size in bytes)....
Created by Dr. Xi on December 04, 2009 04:33:05    Last update: December 04, 2009 04:33:05
Variable Meaning $_ The default or implicit variable. @_ Within a subroutine the array @_ contains the parameters passed to that subroutine. $a, $b Special package variables when using sort() $<digit> Contains the subpattern from the corresponding set of capturing parentheses from the last pattern match, not counting patterns matched in nested blocks that have been exited already. $. Current line number for the last filehandle accessed. $/ The input record separator, newline by default. $| If set to nonzero, forces a flush right away and after every write or print on the currently selected output channel. Default is 0 (regardless of whether the channel is really buffered by the system or not; $| tells you only whether you've asked Perl explicitly to flush after...
Created by Dr. Xi on September 29, 2008 23:05:12    Last update: September 29, 2008 23:06:16
These variables are set or used by the Unix shell to modify its behavior. Variable Description ENV=file Name of script that gets executed at startup; Usually, ENV=$HOME/.kshrc FCEDIT=file Editor used by fc (fix command) command. If $FCEDIT is not defined, use $EDITOR, otherwise use the default (vi or ed). FPATH=dirs Directories to search for function definitions; undefined functions are set via typeset -fu . FPATH is searched when these functions are first referenced. HISTFILE=file File in which to store command history. Default is $HOME/.sh_history for Korn shell, $HOME/.bash_history for Bash. If not set, history is lost after logout. HISTSIZE=n Max number of commands to keep in history. HOME=dir Home directory; set by login from passwd file. IFS='chars' Internal field separators. Default is space, tab, and...
Created by Dr. Xi on September 29, 2008 23:03:40    Last update: September 29, 2008 23:04:08
Variables set automatically by shell: Variable Description $# Number of command-line arguments. $- Options currently in effect (arguments supplied to sh or to set). $? Exit value of last executed command. $$ Process number of current process. $! Process number of last background command. $0 First word; that is, command name. $n Individual arguments on command line (positional parameters). The Bourne shell allows only nine parameters to be referenced directly (n = 1-9); the Korn shell allows n to be greater than 9 if specified as ${n}. $* All arguments on command line ("$1 $2..."). $@ All arguments on command line, individually quoted ("$1" "$2" ...). Variables set automatically by Korn shell: Variable Description ERRNO Error number of last system call that failed. LINENO Current...
Created by Dr. Xi on December 12, 2007 20:30:01    Last update: December 12, 2007 20:32:23
This is a script to tail a log file through the web browser. It uses AJAX, apache web server, mod_python, UNIX utilities tail (requires the --lines switch) and wc . The log file may reside on the web server or any other host accessible from the web server through SSH. Although it's written in python, it should be easy to port to other languages such as Perl. Apache httpd.conf : LoadModule python_module modules/mod_python.so ... Python script: import time, os from os.path import basename ...