Search code examples
bashcut

How to get the selected string from my log file using cut


This is my Log text:

03/17/2014 13:48:40.016- null - PFM_DIP_SERVER_001:Virus infected content detected while scanning file; File name: 2MBVirusTextFile.txt 

From the above Log text i want to get the middle string i.e:

Virus infected content detected while scanning file

How do i get only this string ?

I have written the below code:

result=`tail  /home/eng/Shellscripts/result.txt | grep "PFM_DIP_SERVER_001:" | cut -f1 -d";"  `
echo "$result"

Output:

03/17/2014 13:48:40.016- null - PFM_DIP_SERVER_001:Virus infected content detected while scanning file

Solution

  • You can try this,

    tail result.txt | grep -o "PFM_DIP_SERVER_001:[^;]*" | cut -d: -f2