I am trying to find the number of lines that contain a substring in a file over a given range of lines. E.g. last 100 lines, line 1 to line 5, etc.
Currently for a range I am trying to do:
sed -n '1,5p' $1 >> file.csv
grep -c *"substring"* file.csv
Here $1 is the original file. I am creating a temp file and storing them in there. Is there a better way to do this? As I am not sure if this is working correctly.
As for the last n lines, I am doing:
(tail -n 100 $1) | grep -ic *"substring"* This does not seem to be working.
Wondering where I am going wrong? And how would I go about modifying this for case sensitive/insensitive scenarios.