文章目录
前言
Linux下我们经常会写一些shell脚本来辅助我们学习或者工作,从而提高效率。
之前就写过一篇博客:Linux下利用shell脚本批量产生内容有规律变化的文件
程序
批量造 case 并将 cmd 扔给程序运行
bash
#!/bin/csh -f
if ( $#argv != 2 ) then
echo
echo " Usage: $0 cases temp.cmd"
echo
endif
ls $1 >& list_tmp
# 将 list_tmp 文件中的 pattern_old 关键词都替换成 pattern_new
sed "s/pattern_old/pattern_new/g" list_tmp >& list
rm list_tmp
# 获取 list 中共有多少行
set totalCaseNum = `sed -n '$=' list`
set n = 0
set topPath = `pwd`
mkdir result
foreach case (`cat list`)
#echo case
cd $topPath
cd result
mkdir $case
cd $case
cp $topPath/$2 $2.tmp
# 将 $2.tmp 文件中的 pattern 关键词都换成 $case
sed "s/pattern/$case/g" $2.tmp >& $2
rm $2.tmp
# 程序 运行
program -i $2 -o $2.out >& $2.log
@ n = $n + 1
echo "Now running the $n case " $case ", Total case is " $totalCaseNum
end
批量收集数据汇总
bash
#!/bin/csh -f
if ( $#argv != 1 ) then
echo
echo " Usage: $0 cases"
echo
endif
ls $1 >& list
# 获取 list 中共有多少行
set totalCaseNum = `sed -n '$=' list`
set n = 0
set topPath = `pwd`
foreach case (`cat list`)
#echo case
cd $topPath
cd $1
cd $case
grep "Pattern $case" ${case}.out >> $topPath/result.txt
@ n = $n + 1
echo "Now running the $n case " $case ", Total case is " $totalCaseNum
end