LINKS:

The following will grep all processes for the string "updateStats" and then output the 2nd argument in each line.
<PRE> ps -ef | grep "updateStats" | awk {'print $2'}</PRE>
In the output of "ps -ef", the 2nd argument (just as if each line was a set of command line arguments) is the process id, so the "print $2" prints the 2nd argument in each line.


The following will, in VI, replace the beginning of each line with "BLAH" for the entire file.
<PRE> :1,$ s/^/BLAH</PRE>
The 1,$ indicates the range of lines.
The s/a/b indicates a search and replace of a with B.



SED can be used for quick text string replacements.
ROOTEXP=`echo "abcde" | sed -e 's/a/b/g'`
That will replace all occurrences of "a" with the string "b" in the input string "abcde". The result will be that ROOTEXP will have the value "bbcde". The "g" at the end of the sed string indicates it's a global replace. Remove the g to only replace the first instance.


It's often useful to create files and directories which are structured based on the current timestamp:
YEAR=`date '+%Y'`
MONTH=`date '+%m'`
DAY=`date '+%d'`
LOGDIR=/blah/blip/foo/$YEAR/$MONTH/$DAY
mkdir -p $LOGDIR
NOW=`date '+%Y%m%d.%H%M%S'`
LOGFILE=${NOW}.log


Sometimes it's useful to set variables in one script and then have a bunch of other scripts load the first script. That's what the "source" command is for. For instance:
source /blah/blip/foo/setClasspath.sh

Version 5.1 last modified by Geoff Fortytwo on 11/07/2010 at 19:17

Attachments 0

No attachments for this document
Website Top
Send Me Mail!:
   g42website4 AT g42.org
My Encyclopaedia Blog

Creator: Geoff Fortytwo on 2008/05/12 01:15
Copyright 2004-2007 (c) XPertNet and Contributing Authors
1.3.2.9174