Thanks for reading my question about AWK!!
root@debian:/home/user/Documents/awk# awk '{print}' data 121211111525452255534654436262626234643662612412423136
I need to make a table of how many times each digit happened in this long list of random digits. I’m in a serious emergency situation in real life and need this data sorted out very fast which is why I’m here.
Then I need to assign the results of the count values to variables so that I can now which numbers happened with a higher percentage than others.
I know how to do this using pure bash. However its about 100000 part array so doing this by hand would take me forever. What I really need to find out is how to grab all the times each digit happened inside AWK’s BODY block,without resorting to BASH. Everyone seems to settle for the easy Bash way, I need the real deal inside AWK’s own language so that I can really do what I need to do efficiently.
AWK’s superior language capabilities are really not able to be used fully without knowing how to assign a variable in the AWK BODY of the .awk file correctly so that I can sort huge arrays, like I need to do. Bash is feeling way inferior to AWK. I actually need a huge 1000 part array sorted out. and need to make all sorts of algebraic computations based on all of the variables involved in this array.
I can’t find enough information online, this is an emergency situation, we need this code. Read like 2 guides online and no info on this specifically.
My attempts are
awk -F '5' '{s+=NF-1}END{print s}' data //counts how many times number 5 happened in the data file
This works just like that when run on a file from the command line. It correctly searches the number of times the number 5 happened. However, I can’t do this operation when inside the actual AWK scripts so that I can do this programatically and efficiently. I only know how to execute this command in the shell, which is preventing me from assigning variables and going on with my project effectively and time is running out!!
How do I assign the number of times the number 5 happened in this string to a variable inside AWK that I can use to build an array with? Or should I just use BASH and thats it? Is there a way to assign such values inside awk BODY? I think there must be.
For example, lets say I got:
BEGIN { total=0; } { itemno=$ 1; book=$ 2; bookamount=$ 3*$ 4; total=total+bookamount; print itemno," ", book,"\t","$ "bookamount; } END { print "Total Amount = $ "total; }
I specifically need an array that counts the number of times each individual number/digit type happened in this string of random numbers.
number 5 happened 65 number 11 happened 54 times
I need to use inside body block type variables and not BASH variables.
Any insight would really help me out. Thanks.