I want to count all occurances of any variable in parenthesis after patterns, for files in a directory that have a specific extension. Each file may contain the pattern on multiple records/line.
So far I can process the files and store the results in an array but seems the array gets overwritten with each new file I process. How can I retain the array value?
#!/bin/bash
for x in `find . $PROGFILES -name "*.fgl"`
do
awk -f <(cat - <<-'EOF'
/ envget | env-get | \"envget\" | \"env-get\" /
{
gsub( /get-env/, "envget") ;# removes hypens
gsub( /.*envget/, " envget")
gsub( "\\concat" ,"") ;# removes concat
gsub( "\\substring" , "") ;# removes substring
for (i = 1; i<= NF; i++) {
if ( substr( $i, 1, 6) == "envget" ) {
lenofget = 8;
} else {
lenofget = 0;
}
if ( lenofget != 0 ) {
gsub("\\envget" , "",$i) ;#removes envget
gsub ( /\)\.*/, "",$i) ;#removes everything after a closing parenthesis
gsub ( /\47/, "",$i) ;#so used octal instead
gsub ( /\(/, "",$i) ;#removes paraentheses
gsub ( /\"/, "",$i) ;#removes double quotes
gsub ( /\,.*/, "",$i) ;#removes everything after a , This is for any concat syntax
gsub ( /[\/].*/, "",$i) ;#removes everything after a forward slash
narr[$i]++
}
}
}
END {
for (y in narr) {
printf("%s - %d\n",y, narr[y])
}
}
EOF
) $x
done
Typical records/lines in a file with the pattern/s would be:
if envget("SYPSDATA") in {SPACES "."}
set lf-path = "envget"('SYPSCTRL')
if env-get(concat("LOG_PRINTER",service-centre)) != spaces
trconcat(env-get("TMPDIR"),"/ps_xxx_temp.psv")
envget(substring(ws-envprinter1,1,strlen(ws-envprinter1)))
set lf-path = "envget"('SYPSCTRL')
display bitmap concat(envget('BTS')'/images/repedge.gif') @19,44
Given there are multiple files with multiple pattern matched lines I'm expecting to get output like this (where the numbers are total count found in every file).
BTS - 15
LOG_PRINTER - 7
ws-envprinter1 - 3
SYPSDATA - 120
TMPDIR - 130
SYPSCTRL - 200