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.
Search This Blog
Showing posts with label Variables. Show all posts
Showing posts with label Variables. Show all posts
Friday, May 08, 2015
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]])}
Tuesday, June 28, 2011
Shell Scripting: basename variable
"${0##*/}" is the equivalent of "basename $0".
I.e. From /usr/bin/sh we get just sh.
Also try this to execute commands $(shell command)
I.e. From /usr/bin/sh we get just sh.
Also try this to execute commands $(shell command)
Thursday, May 17, 2007
Shell scripting: Testing empty variables
$V="xNotEmpty" if [ x$V = "xNotEmpty" ] then echo "\$V not empty" else echo"\$V is empty" fi Or: if [ "$V" = "" ] then echo "\$V is empty fi
Friday, September 01, 2006
Shell Scripting: Special Variables
Subscribe to:
Posts (Atom)