This issue is related to Using bash shell function inside AWK
I have this code
#!/bin/bash
function emotion() {
#here is function code end with return value...
echo $1
}
export -f emotion
#I've put all animals in array
animalList=($(awk '{print $1}' animal.csv))
#loop array and grep all the lines form the file
for j in ${animalList[@]}
do
: #here I'am running a bash script calling emotion function
grep $j animal.csv | awk '{for(i=2;i<=NF;i++){system("bash -c '\''emotion "$i"'\''")}}'
done
and I have this file:
cat smile happy laugh
dog angry sad
mouse happy
wolf sad cry
fox sleep quiet
The output should like this:
smile
happy
laugh
angry
sad
happy
sad
cry
sleep
quiet
The issue it tells me bash: emotion: command not found
According to akarilimano's comment here
this is not working on my Ubuntu 16.04. This is strange, because it used to work "on Ubuntu 14.04.
So how to do it in newer versions?
awk '{$1=""; for(i=1;i<=NF;i++) printf("%s\n", $i) }' yourfile
should get the desired result4.4.12
on arch linux. What are you running this on?