Results 1 to 3 of 3
awk: How pass parameters to the function, called from inside awk ?
Hello, Experts!
Please, help me to figure this out:
Here is sample function:
Code:
$ testfn() { echo ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 02-10-2013 #1Just Joined!
- Join Date
- Feb 2013
- Posts
- 2
awk: How pass parameters to the function, called from inside awk ?
awk: How pass parameters to the function, called from inside awk ?
Hello, Experts!
Please, help me to figure this out:
Here is sample function:
awk example:Code:$ testfn() { echo "${1} world"; } $ testfn hello hello world
Code:$ echo "something bla bla2"|awk '$1 ~/something/ { print $1; print $0; }' something something bla bla2
Now, I want to change "something" to "something world" using created above function, when printing it as a whole line, by passing first awk "column element" as a parameter:
^^Above doesn't work^^Code:$ echo "something bla bla2"|awk '$1 ~/something/ { $1="'"$(testfn) $1"'" ; print $0 }' world bla bla2
^^Above doesn't work^^Code:$ echo "something bla bla2"|awk '$1 ~/something/ { $1="'"$(testfn)"$1'" ; print $0 }' world bla bla2
^^Above doesn't work^^Code:$ echo "something bla bla2"|awk '$1 ~/something/ { $1="'"$(testfn)"'$1" ; print $0 }' world$1 bla bla2
Is thee any way to pass parameters from awk to the function inside awk ?
Thanks!
- 02-10-2013 #2Linux Newbie
- Join Date
- Nov 2012
- Posts
- 134
hi,
why don't you declare the function inside awk ?
Code:awk 'function sayHello(arg) { print "Hello "arg } /^something$/{sayHello($1)}'
- 02-10-2013 #3Just Joined!
- Join Date
- Feb 2013
- Posts
- 2
Thanks! And would it be possible to call shell function from declared function inside awk ?


Reply With Quote
