$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
Search This Blog
Thursday, May 17, 2007
Shell scripting: Testing empty variables
Wednesday, May 16, 2007
awk
Using shell variables with awk.
1. awk "/$func/"'{print $0}' filename
2. awk -v pat=$func '/pat/{print $0}' filename
Using fields in search pattern
For a similar match:
1. awk '$1~/pattern/{print $0}' filename
For a precise match:
2. awk -F":" -v user=$U '$1 == user {print $0}' filename
1. awk "/$func/"'{print $0}' filename
2. awk -v pat=$func '/pat/{print $0}' filename
Using fields in search pattern
For a similar match:
1. awk '$1~/pattern/{print $0}' filename
For a precise match:
2. awk -F":" -v user=$U '$1 == user {print $0}' filename
Subscribe to:
Posts (Atom)