Sathiya saravana Babu Sathiya saravana Babu - 3 months ago 9
Linux Question

Find the duplicate sentence with count after removing some content in linux

I am fresher in Linux command

In my log file, I have saved the content like that

2016-08-11 11:47:19 To: saravana@adodis.com ==> /var/log/testmail.php
2016-08-11 11:47:41 To: sathiyasaravanababu91@gmail.com ==> /var/sentora/hostdata/zadmin/public_html/hostingraja_info/testmail.php
2016-08-11 11:48:06 To: sathiyasaravanababu91@gmail.com ==> /var/sentora/hostdata/zadmin/public_html/hostingraja_info/testmail.php


I have used the below command

sort mail_php.log | uniq -c


that produce the following output

1 2016-08-11 11:47:19 To: saravana@adodis.com ==> /var/log/testmail.php
1 2016-08-11 11:47:41 To: sathiyasaravanababu91@gmail.com ==> /var/sentora/hostdata/zadmin/public_html/hostingraja_info/testmail.php
1 2016-08-11 11:48:06 To: sathiyasaravanababu91@gmail.com ==> /var/sentora/hostdata/zadmin/public_html/hostingraja_info/testmail.php


but I need the following result

1 To: saravana@adodis.com ==> /var/log/testmail.php
2 To: sathiyasaravanababu91@gmail.com ==> /var/sentora/hostdata/zadmin/public_html/hostingraja_info/testmail.php


is it possible via a command ? or else needed to write a shell script?

Could you please help me ?

Answer

You can try this, its a basic step to start with:

awk '{print $3 " " $4 " " $5 " "  $6}' mail_php.log | uniq -c
Comments