How to get filename from the fullpath and how to grep multiple strings

Hi,

New to shell scripting....
I have log file content as below:

I have to count the number of occurences of ERROR or INFO Messages.
So, I cut 5 th column and uniquly sorted and redirected it to new.txt file.

But I want copy to S*/Filename and T*/Filename of respective ERROR or INFO messages,uniquly sorted to new.txt file.

I tried awk command ..but it failed to copy to new.txt file.

Once this is done I have to check for the occurences of ERROR string. So for that I searched for egrep and tried to use, but output is incorrect.
Final output i am looking for:

Do anybody have any idea???

Thanks in advance..

Try:

perl -ne '/(?<=logs\/)([^\/0-9]+).*?\/([^:]+).*(?<=] )(.*?)$/;$a{"$1*/$2,$3"}++;END{for $i (keys %a){print "$i, $a{$i}\n"}}' logfile
1 Like

Another approach:

awk '/ERROR|INFO/{sub(".*logs/","");sub(":.*","");a[$0]++}
END{for (i in a)print i, "Exception is caught", a}' file
1 Like
awk -F':|\] ' '/ERROR|INFO/{sub(".*logs/","",$1);a[$1 OFS $NF]++}END{for(i in a)print i,a}' file
1 Like
 $ ruby -ne 'BEGIN{h={};h.default=0};(a=$_.scan(/^.*logs\/(.[^\/]*)(.[^:]*)/).join; h[a]+=1) \ 
   if /ERROR|INFO/;END{h.each{|x,y| print "#{x} Exception caught #{y}\n" } } ' file  
1 Like

Thanks All for reply...