bash脚本,分析报告文件 [英] Bash script that analyzes report files

查看:145
本文介绍了bash脚本,分析报告文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我会用它来分析当前目录中所有报告文件以下bash脚本:

I have the following bash script which I will use to analyze all report files in the current directory:

#!/bin/bash    


# methods
analyzeStructuralErrors()
{ 
    # do something with $1
}

# main
reportFiles=`find $PWD -name "*_report*.txt"`; 
for f in $reportFiles
do
    echo "Processing $f"
    analyzeStructuralErrors $f
done

我的报告文件格式为这样的:

My report files are formatted as such:

Error Code for Issue X - Description Text - Number of errors.
col1_name,col2_name,col3_name,col4_name,col5_name,col6_name
   1143-1-1411-247-1-72953-1
   1143-2-1411-247-436-72953-1
   2211-1-1888-204-442-22222-1
Error Code for Issue Y - Description Text - Number of errors.
col1_name,col2_name,col3_name,col4_name,col5_name,col6_name
   Other data
   .
   .
   .

我正在寻找一种方式来通过每个文件和汇总报表数据。在上面的例子中,我们有X型,这我想在analyzeStructural处理的两个独特的问题。其他类型的问题可以在此例程被忽略。任何人都可以提供如何做到这一点建议吗?我想读的每一行,直到我打了一个错误,基本上,并把这些数据转换成某种数据结构。

I'm looking for a way to go through each file and aggregate the report data. In the above example, we have two unique issues of type X, which I would like to handle in analyzeStructural. Other types of issues can be ignored in this routine. Can anyone offer advice on how to do this? I want to read each line until I hit the next error basically, and put that data into some kind of data structure.

推荐答案

的建议戴夫贾维斯, AWK 将:

As suggested by Dave Jarvis, awk will:


  • 处理这不是庆典
  • 更好
  • 是相当容易学习

  • 可能提供的bash的地方可用

我从来没有更远看起来比的AWK手册

I've never had to look farther than The AWK Manual.

如果你使用一个一致的字段分隔列名和两个数据列表它将使事情变得更容易。也许你可以通过做一些pre-处理在庆典剧本 SED 喂食前 AWK 。无论如何,看看多维数组阅读多行手册中

It would make things easier if you used a consistent field separator for both the list of column names and the data. Perhaps you could do some pre-processing in a bash script using sed before feeding to awk. Anyway, take a look at multi-dimensional arrays and reading multiple lines in the manual.

这篇关于bash脚本,分析报告文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆