使用grep / awk从日志文件中提取文件名

时间:2016-03-17 01:10:04

标签: bash awk

我想从日志中找到该文件的名称。我使用awk命令尝试了它,但无法成功。

我试过了:

FILE=`grep "^.java" /home/jimit/TestLogs.log | awk '{print $2}' | awk -F ':' '{print $1}'`
echo $FILE

示例日志:CommentService

Caused by: com.ofss.fc.framework.exception.BusinessException: The memo start date cannot be earlier than the process date.
    at com.ofss.fc.domain.party.service.core.CommentService.validateMemos(CommentService.java:474)
    at com.ofss.fc.domain.party.service.core.CommentService.addMemosToParty(CommentService.java:655)

1 个答案:

答案 0 :(得分:1)

试试这个

$ grep -o "[^.(]*\.java" log  

CommentService.java                                                                                                   
CommentService.java