csh 脚本批量处理文件并将文件扔给程序

文章目录

前言

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
相关推荐
许白掰43 分钟前
Linux入门篇学习——Linux 工具之 make 工具和 makefile 文件
linux·运维·服务器·前端·学习·编辑器
longze_75 小时前
Ubuntu连接不上网络问题(Network is unreachable)
linux·服务器·ubuntu
Dirschs5 小时前
【Ubuntu22.04安装ROS Noetic】
linux·ubuntu·ros
qianshanxue115 小时前
ubuntu 操作记录
linux
AmosTian8 小时前
【系统与工具】Linux——Linux简介、安装、简单使用
linux·运维·服务器
这我可不懂10 小时前
Python 项目快速部署到 Linux 服务器基础教程
linux·服务器·python
车车不吃香菇11 小时前
java idea 本地debug linux服务
java·linux·intellij-idea
tan77º11 小时前
【Linux网络编程】Socket - TCP
linux·网络·c++·tcp/ip
kfepiza12 小时前
Linux的`if test`和`if [ ]中括号`的取反语法比较 笔记250709
linux·服务器·笔记·bash
CodeWithMe12 小时前
【Note】《深入理解Linux内核》 第十九章:深入理解 Linux 进程通信机制
linux·运维·php