Sorry.. I didnt mention properly in the question i asked.. I want to assign the $3 to a variable so that I need to use that variable in the remaining part of script.. can yu pls let me know.. ur help appreciated...
function getthree() {
mfn=$1
fn=$2
out=`awk -v fn=$fn ' {
if ($3) {
print $3 ; print $3 >> fn
close(fn)
}
}' $mfn`
test ! -z $out && export out && return $?
}
Now all you have to do is call;
getthree filename tmpfilename
hi marsd,
thx for your reply.. am new to scripting and 've never used a function call.. can u pls explain me how do u call this fn ? and can u explain this line
getthree filename tmpfilename ( i know this is the call to the function.. but dont know whats that tmpfilename and filename... ur help appreciated...
To use the function, call it as written at the point in your script where you would do your awk {print $3}, etc.. line
The first parameter is the name of the file you wish awk to read from,the second parameter is the tmpfile you want
results written to. The result of reading field three is
exported into your shell global environment if not empty and can be accessed as the variable out:ex: echo $out.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.