我正在解析日志并根据错误我想找到导致过去7天出现以下错误的列表存储库:
2016-09-21 14:57:11,234 WARN - Exception during FishEye Incremental Indexing of TEST-REPO1: com.cenqua.fisheye.config.ConfigException: com.atlassian.fisheye.dvcs.handler.DvcsProcessException: Error while communicating with VCS: GitLab: The project you were looking for could not be found.
2016-09-21 15:07:23,379 WARN - Exception during FishEye Incremental Indexing of TEST-REPO2: com.cenqua.fisheye.config.ConfigException: com.atlassian.fisheye.dvcs.handler.DvcsProcessException: Error while communicating with VCS: GitLab: The project you were looking for could not be found.
为了得到它我使用sed:
sed -n "/$last_day/,/$current_date/p" /home/atlassian/crucible.data/var/log/fisheye.out | grep -i "project you were looking" | awk '{ print $11 }' | awk '!x[$0]++'
但我得到了:
TEST-REPO1:
TEST-REPO2:
you
found.
结果我想:
TEST-REPO1
TEST-REPO2
答案 0 :(得分:3)
awk -F'[: ]' -v l="$(date +'%Y-%m-%d' -d' 7 days ago')" '
/project you were looking/ && $1>=l && !seen[$14]++{
print $14
}' log
您当前的日志输入文件21-09-2016
早于159
天,就像今天27-02-2017
一样,所以使用上面的命令您无法获得输出以检查命令是否正常工作您可以尝试以下
awk -F'[: ]' -v l="$(date +'%Y-%m-%d' -d' 159 days ago')" '
/project you were looking/ && $1>=l && !seen[$14]++{
print $14
}' log