Some times we need to pass external shell variables inside awk statement. Here is a way to do it
suppose I want to use $user in my awk command
$ export user=uid #$user is defined
Pass it to awk command with -v option
$ cat /etc/passwd|tail -1|awk -v var=$user -F":" '{print "Your " var " is " $1}'
o/p: Your uid is guruss1
No comments:
Post a Comment