Friday, February 2, 2007
Accessing Env Variable in AWK
Suppose we have a file with some statistics for users in the system.
$ cat oot.txt
user5|23|killall|23-10-2007
user2|21|rm -rf|23-10-2007
user3|0|killall|23-10-2007
user8|12|ups_sync|23-10-2007
user6|23|killall|23-10-2007
The logged user is "user8"
$ echo $USER
user8
Now to print the line for the logged user, we have to use ENVIRON
$ awk -F "|" '$1==ENVIRON["USER"] {print $0}' oot.txt
user8|12|ups_sync|23-10-2007
Subscribe to:
Post Comments (Atom)
© Jadu Saikia www.UNIXCL.com
1 comment:
Hi Guti Junix OS Xikiba lagiba.
Post a Comment