Sir, I have tried all possible combinations of $k and k. And neither of them give me my expected output. Either I am not able grasp what you are telling me or you don't understand what I want. Or maybe it can't be done all together.
I posting various combinations of scripts that I have tried with their respective outputs-:
First Sample Script-: (Where all $k
has been replaced with k
)
function my_local_function () {
echo $1;
}
export -f my_local_function
echo $1 | awk -F"/" '{ for (k=1;k<=NF;k++) { if ( k == "a" ) { system("my_local_function" k) } else { print k } } }'
Output-:
1
2
3
4
As you can see above no errors but I don't get my expected output. Since I am using k
and not $k
. Since k represents the loop variable and not its value.
Second Sample Script-: (Where I am using system("my_local_function" k)
and $k in all other places)
function my_local_function () {
echo $1;
}
export -f my_local_function
echo $1 | awk -F"/" '{ for (k=1;k<=NF;k++) { if ( $k == "a" ) { system("my_local_function" k) } else { print $k } } }'
Output-:
sh: my_local_function1: command not found
b
c
d
Third Sample script: (Where I am using system("my_local_function k")
and $k
in all other places)
function my_local_function () {
echo $1;
}
export -f my_local_function
echo $1 | awk -F"/" '{ for (k=1;k<=NF;k++) { if ( $k == "a" ) { system("my_local_function k") } else { print $k } } }'
Output-:
k
b
c
d
Again not a correct output but error free.
Fourth Sample Script-: (Where I am using system("my_local_function $k")
and $k
in all other places)
function my_local_function () {
echo $1;
}
export -f my_local_function
echo $1 | awk -F"/" '{ for (k=1;k<=NF;k++) { if ( $k == "a" ) { system("my_local_function $k") } else { print $k } } }'
Output-:
b
c
d
One blank line and the rest of the output is OK.
So basically what I want to do is call a BASH function from awk and pass the value of an awk variable as an argument. CAN IT BE DONE ?
And please can you post an entire working script next time rather than telling me what to do. It will avoid any further confusions.