grep sorting/formatting

Hi,

I currently have many log files for different webpages inside the folder /log/. The program allows the user to enter a month and then the grep function searches for it, the command i used is below:

grep -c "$month" ./log/*.log

This works and i can ascertain the number of matches, but I cannot find out how to format the name of the .log and the number of matches into two seperate columns. Kind of like:

Log Name Matches
--------------- --------

soccerscore.log 40
soccerfaqs 20

Any ideas how to do this?

At the moment its like

./logs/soccerscore.log:40

-Thanks for any help

Use sed for this.

grep -c "$month" ./log/*.log | sed 's/\.\/log\///g' | | sed 's/:/ /g'

or awk

grep -c "$month" | awk -F: {print $1,"   ",$1}'

It just does the same output as it does before when I use this.

The other awk one doesnt display the hits, it just displays the directory of the wepages in two columns.

grep -c "$month" ./log/*.log | { read a; echo ${a##*/} ; } | sed -e "s_\(.*\):\(.*\)_\1 \2_g"
 grep -c "$month" ./log/*.log | sed 's/\.\/log\///g' |  sed 's/:/ /g' 

This very much works for me..
All that command does is to remove the "./log/" from the listing and replace ":" with " "

Ah, sorry I must have missed a bit of the code, was doing it early in the morning �_�.

Is there anyway to format that so the webpages are in one colum and the seperated hits in another?

Thanks for the help btw :slight_smile:

what kind of formatting you want..? You can put a delimiter.. that should work..

Did you try the above ?

I want it in two columns, kinda the same as in a table format, like in my original porst.

I tried putting a "\t" in the sed, whilst this spaced out the matches, they arent all aligned in a second column, due to the smaller file names.

Im thinking the 'printf' command may be better spacing the matches out into another column, though im having trouble putting it into the 'sed' sequence.

I tried this, but it only returned one log