Home > other >  How to pick words in a log file using shell script
How to pick words in a log file using shell script

Time:05-14

I am trying to pick words start with "Approved by" and end with after "AAAA" letters . here is log file.

Test worker] INFO cyyom.bghhht.gsghhj.dijjkkgital.dggcf.applicationservice.service.RequestServiceImpl - Approved List : 
[AssignAccountApplicationRequestDto [status=true, requestId=1, backendData=BackendPopupDto [userID=0, companyId=0, ApplicationId=0, 
userType=Test, corpId=0, revenueOwner=notnull, requestedDate=null]]] , Rejected List : [AssignAccountApplicationRequestDto [status=false, requestId=11, backendData=null]]
Approved by ha:////4P4ei7QWIY1VDT3ygY1geg0Q82Jj2AqLzGAAAAmh LCAAAAAAAAP9b85aBtbiIQTGjNKU4P08vOT vOD8nVc83PyU1x6OyILUoJzMv2y /
JJUBAhiZGBgqihhk0NSjKDWzXb3RdlLBUSYGJk8GtpzUvPSSDB8G5tKinBIGIZ sxLJE/ZzEvHT94JKizLx0a6BxUmjGOUNodHsLgAyxEgY /
dLi1CL99OKCxJTczDwAUT2GdsMAAAAXLPortal Administrator

I tried

awk -F'=' '/^Approved by / && NF>=2{print $NF}' log

expected output

XLPortal Administrator

CodePudding user response:

With your shown samples please try following awk program.

awk '
match($0,/AAAA[ =].*/){
  val=substr($0,RSTART,RLENGTH)
  gsub(/AAAA[ =] /,"=",val)
  print val
}
' Input_file

CodePudding user response:

Using sed

$ sed -n s'/.*AAA\([[:alpha:] ]*\)$/\1/p' input_file
XLPortal Administrator
  • Related