Sample code using getopt
while getopts :f:cuh OP
do
case ${OP} in
f) SERVERS=${OPTARG}
;;
c) if [ "${SERVERS}" != "false" ]
then
check
else
usage
fi
;;
u) if [ "${SERVERS}" != "false" ]
then
cd ${BASE}
fi
;;
*|h)
usage
;;
esac
done
Search This Blog
Friday, September 18, 2015
Tuesday, August 11, 2015
Replace spaces with commas using sed
sed 's/ \{1,\}/,/g'
Friday, May 08, 2015
Use variable in search pattern in awk
Passing a variable to awk and using it in the search pattern.
awk -v string="$STRING" -f script.awk [filename]
Script extract:
$0 ~ string {
print $0;
}
Note:
On Solaris use nawk.
awk -v string="$STRING" -f script.awk [filename]
Script extract:
$0 ~ string {
print $0;
}
Note:
On Solaris use nawk.
Tuesday, April 14, 2015
Match IP numbers with regex.
Print any
IP address talking on port 21 in coming or out going.
Change the port number to any port that needs to be matched.
netstat -na | perl -ne '/((\d{1,3}\.){4}21)/ && print ;'
Monday, January 26, 2015
Variable assigments
Validating positional parameters.
The below example will print a usage message if there is no 2nd position paramaeter.
PACKAGE=${2:?$(usage ${SERVERLIST} [Package name:Version:Package file[:Dependent service]])}
The below example will print a usage message if there is no 2nd position paramaeter.
PACKAGE=${2:?$(usage ${SERVERLIST} [Package name:Version:Package file[:Dependent service]])}
Subscribe to:
Posts (Atom)