So, I have three problems that cover this subject.
First one asks me to find the number of fields in the file that contain the substring "he". I found the number of fields, but the problem I have is that they are displaying by each record. I want to add all of the records' fields together.
With this same text document:
"The quick brown fox jumped over the lazy dog's back.
The rain in Spain falls mainly on the plain.
The rain in Spain also falls on the mountains."
My code looks like this:
{print "Number of fields in record containing 'he': " index($0, "he")}
It is giving me this result:
"Number of fields in record containing 'he': 2
Number of fields in record containing 'he': 2
Number of fields in record containing 'he': 2"
What I want it to do is print
"Number of fields in file containing 'he': 6"
How would I accomplish that?
These are the two other problems, of a very similar type: I want to find the number of times the letter n appears in the text file, but I do not know how to add all the records' results together. My current code looks like this:
{print "Number of 'n' in record: " gsub(/n/, "")}
This gives me the result of:
"Number of 'n' in record: 1
Number of 'n' in record: 6
Number of 'n' in record: 6"
Instead, I need it to say
"Number of 'n' in file: 13"
The last problem is essentially the same, but instead of 'n', I need to look for the number of 'la' in the file.