ASIC/FPGA Design and Verification Out Source Services
A script to search into multiple files and generate a report, using for f loop style
Many times I need to search in a list of files some pattern and generate a report with finding. In the last example I needed to search into 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 the regression file name and directory as well as the test name and the key word, which was found.
While usually my script are heavily based on | xargs -n1 | xargs -i=, this one is less dependant on that. This results in much simpler scripts.
When I wrote older script, I was always extremely short of time. So the idea was: have the scan and file lookup simple (xargs) in expense of some more complexity in the scripts.
This script still uses (xargs), but all the rest is done in for f loop.
Here is a very simple script, which uses for f loop (similar to perl's foreach):
#!/bin/bash
#how to run the script
#~/bin/grep_error_a.unx "Error display int" "ncsim.log"
#~/bin/grep_error_a.unx "Error display int" "specman.elog"
echo "grep -l \""$1"\" \$1" > tmp
chmod u+x tmp
#reset counter
cnt="0"
for f in $(find . -name "${2}" | xargs -n1 | xargs -i= ./tmp =); do
echo "----------------------------------------------------------------------" >> grep_error.txt
echo $cnt" "$f >> grep_error.txt
grep "sn load " $f | sed 's/sn load //' | sed 's/ncsim> *//' >> grep_error.txt
echo $1 >> grep_error.txt
#increment counter
cnt=$[$cnt+1]
done
The report looks like:
----------------------------------------------------------------------
0 ./kuku_tests/run_11/ncsim.log
tests/tc.42.Kukuss_gegfpt_tx_pkt_for_kMon_line_ge/tc.42.Kukuss_gegfpt_tx_pkt_for
_kMon_line_ge.e
Dut error
----------------------------------------------------------------------
1 ./kuku_tests/run_12/ncsim.log
tests/tc.42.Kukuss_gegfpt_tx_pkt_for_kMon_line_ge/tc.42.Kukuss_gegfpt_tx_pkt_for
_kMon_line_ge.e
Dut error
|