I am trying to use awk and its split function to get the number of tokens in a string that are seperated by underscores.
ex_alex_is_testing_this_script_ex would return 7. It works when I directly put the string in. However, I can not get it to work when I try to refer to a variable used earlier in my Script. I think this is because of the BEGIN statement. Any ideas to get this to work with a variable that was used prior.
WORKING:
'BEGIN {print split("ex_alex_is_testing_this_script_ex", myarray, "_")}'
--> returns 7
NOT WORKING
'BEGIN {print split($something, myarray, "_")}' i.e --> I want to count how many underscores are in the $something.
Thanks for your help,
Alex
Montreal, Canada