ASIC/FPGA Design and Verification Out Source Services
A script to search into multiple files and generate a report
Many times I need to search in a list of files some pattern and generate a report of what was found. In the last example, I needed to search in multiple files, which was the result of regression. From some reason the tool did not generate a good report.
This script simply gets a key word to look, and searches each file. If the key word is found, an entry is created in the log. The entry consists of the regression file name and directory as well as the test name and the key word, which was given as a key word.
Here is a very simple script that can help:
#!/bin/bash
cmd="grep "${1}" "${2}
$cmd
#0 means grep found the pattern
if [ $? -eq 0 ] ; then
cmd="grep \"sn load \" "${2}" | sed 's/sn load //' | sed 's/ncsim> *//'"
#cmd="grep \"sn load \" "$2
#Creates an executable file named tmp
echo $cmd > tmp
echo "echo "$2 >> tmp
echo "echo "$1 >> tmp
chmod u+x tmp
./tmp >> grep_error.txt
fi
Note: before running the script you need to erase, once at the very first time, the output file, grep_error.txt, if it does exist. The script does not erase it, but rather adds entries to it.
Invocation: I usually use xargs.
cat 1 | xargs -n1 | xargs -i= ~/bin/grep_error.unx "Register mismatch" =
A word about xargs: Because I use it in the invocation, it easier to specify on which files the script works, while the script itself becomes a bit more complicated. I need to build an executable file, namely tmp, and run it.
A simple script is given in the next link. Once I had some free time, I re-write it using a for f (similar to perl's foreach style):
grep error report using for f style
The scripts results are accumulative. So each time you fire the command, shown before, data is accumulated into the report.
The most up-to-date version of the script is found at:
grep error report
|