For example, if I want to search for a text file/script that contains the most number of for loop statements, and have it displayed on the screen, How would I do that?© BrainMass Inc. brainmass.com October 10, 2019, 12:35 am ad1c9bdddf
Assuming single occurrence of search string (for example, "for") in a line, following simple pipeline will do the job.
grep -c "for" * | sort -nrt: +1 | head -1
Above pipeline command ...
Solution first gives a simple shell pipeline to achieve the goal and then shows how it can be put in a script form.