testlog=$1
uniteBundleLine $testlog ${testlog}.tmp
cat ${testlog}.tmp | sed '/^$/d' | awk '{print $1}' | sort | uniq -c > ${testlog}.tmp2
cat ${testlog}.tmp2 | grep -v "iss\|clocks\|cycle\|fetch" | sort -k1 -g | tee ${testlog}.freqtab
uniteBundleLine.cpp
程序代码:
#include "stdio.h"
#include "string"
using namespace std;
char fsm[2][256];
void initfsm()
{
const int line_len=sizeof(char)*256;
memset(fsm[0],0,line_len);
memset(fsm[1],1,line_len);
fsm[0]['"']=1;
fsm[1]['"']=0;
}
int main(char argc, char**argv)
{
int state=0;
unsigned char c;
std::string s;
if ( (argv[1] == NULL) || (argv[2] == NULL) )
{
printf("please check the input parameter.\n");
return 1;
}
FILE *fin=fopen(argv[1], "r");
FILE *fout=fopen(argv[2], "w");
if ( (fin == NULL) || (fout == NULL) )
{
printf("please check the name of input files.\n");
return 1;
}
initfsm();
while(fscanf(fin,"%c",&c)!=EOF)
{
state=fsm[state][c];
switch(state)
{
case 1:
if(c=='\"')
{
fputc('\n',fout); // 将第一个引号换成空格
}
else
fputc(c,fout);
break;
default:
if(c=='\n')
{
fputc(c,fout);
}
break;
}
}
fclose(fin);
fclose(fout);
return 0;
}