Skip to content
Advertisement

Get information in the Log file

I have a log file and below is sample log in that file. I changed only here column 3rd and 4th as SourceNo,Destination for reference.

3,16/04/17 11:32:16,Destination,Source,0,5192,16345,596444542977,16403,CrystalTech01,sup-mitto-003__0,2,3,,0,0,,0,0,107,0,0,0,2,,,,,,,,,,0,

my requirement – I need to get separately, Source wise total count that sent to Destination begin with 44 code.

i tried with grep and awk but it didn’t work.

appreciate your help.

logs in the file –

8,16/04/17 16:18:12,2609xxxxxx,Zanaco,0,5192,0,596xxxxxx,16403,CrystalTech01,,5,1,,0,0,,1,0,108,0,0,0,,3,0,0,0,0,0,2609641xxxxx,Zanaco,,,
8,16/04/17 16:18:12,2509xxxxxx,Zanaco,0,5192,0,5964509520xxxxx,16403,CrystalTech01,,5,1,,0,0,,1,0,111,0,0,0,,3,0,0,0,0,0,260979xxxxx,Zanaco,,,
5,16/04/17 16:18:12,2609xxxxxx,Zanaco,0,5192,16329,5964509xxxxx,16403,CrystalTech01,sup-messagebird-eur-003__0,5,1,,0,0,,,0,108,0,0,0,,3,0,260964xxxx,Zanaco,,,0.005,16403,1.0,16329,
5,16/04/17 16:18:03,47783xxxxx,BetBright,0,4482,6121,596450951xxxx,0,0,sup-clx-uk__0,2,3,,0,0,,0,0,0,0,0,0,3,,,,,,,,,,1,
3,16/04/17 16:18:03,44783xxxxxx,BetBright,0,4482,6121,59645095xxxxx,0,0,sup-clx-uk__0,2,3,,0,0,,0,0,0,0,0,0,3,,,,,,,,,,1,
3,16/04/17 16:18:04,447837xxxx,BetBright,0,4482,6121,59645095xxxxxx,0,0,sup-clx-uk__0,2,3,,0,0,,0,0,0,0,0,0,3,,,,,,,,,,1,
3,16/04/17 16:18:04,447584xxxxx,BetBright,0,4482,6121,5964509509xxxxx,16448,kelfast-001,sup-clx-uk__0,2,3,,0,0,,0,0,198,0,0,0,2,,,,,,,,,,0,

sample output that I need –

Zanaco  6574   
BetBright 456

Advertisement

Answer

If I get your intent correctly, you want to count rows source wise for records that have destination starting with 44.

I have used some dummy data.

You can use this:

$ cat data 
3,16/04/17 11:32:16,441,8,0,5192,16345,596444542977,16403,CrystalTech01,sup-mitto-003__0,2,3,,0,0,,0,0,107,0,0,0,2,,,,,,,,,,0,
3,16/04/17 11:32:16,442,1,0,5192,16345,596444542977,16403,CrystalTech01,sup-mitto-003__0,2,3,,0,0,,0,0,107,0,0,0,2,,,,,,,,,,0,
3,16/04/17 11:32:16,443,1,0,5192,16345,596444542977,16403,CrystalTech01,sup-mitto-003__0,2,3,,0,0,,0,0,107,0,0,0,2,,,,,,,,,,0,
3,16/04/17 11:32:16,413,1,0,5192,16345,596444542977,16403,CrystalTech01,sup-mitto-003__0,2,3,,0,0,,0,0,107,0,0,0,2,,,,,,,,,,0,
$ awk -F , '$3 ~ /^44/ {a[$4]++;} END {for(i in a) print "Source: " i " has count " a[i]}' data
Source: 1 has count 2
Source: 8 has count 1
$
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement