Search code examples
linuxshellgreptabular

File name along side count the number elements divided per 2


I have several files I want to get the number of a particular element. But I then want to divide that count per 2.

The final final I wish to get is a table. The first column would be file name and the second the elements count divided per 2.

I have tried this

for i in *; do echo $i && grep -c elements $i ; done

My output give

file1

count

file2

count

But I would like to get

file 1 count/2

file 2 count/2

Thanks in advance,


Solution

  • for i in *; do echo -e "$i" '\t'  $(($(grep -c elements $i) /2)) ; done