Skip to content
Advertisement

I have three files and I want to count the concurrences from first 10 lines of the files and summation of it?

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"
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement