I Used this command to count the concurrences of the entire file.
JavaScript
x
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.
JavaScript
head -n 10 fileName | grep -o "pattern" | wc -l
or just
JavaScript
head -n 10 fileName | grep -c "pattern"