Storing standard output in AWK program variable
Within my awk script, I had to perform a search and capture the results of the search operation within a program variable for further processing.
To perform the search - grep was used and it was invoked within awk using the system function. The hurdle was to assign the result of the operation to a program variable in awk.
The system function returns an error code, so a direct assignment was ruled out. The workaround (or may be the right solution) is to make use of the getline function.
The code snippet is given below
cmd = 'grep "LDAP:" applnList.txt > tmpfile' ;
system(cmd) ;
getline expectedLine < "tmpfile" ;

0 Comments:
Post a Comment
<< Home