I Used this command to count the concurrences of the entire file.
grep -o "pattern" fileName | wc -l
I need to find out the numbers of concurrences from only first 10 lines
Advertisement
Answer
You can use head
to read only first 10 lines of the file.
head -n 10 fileName | grep -o "pattern" | wc -l
or just
head -n 10 fileName | grep -c "pattern"