[英]run shell script on files in multiple directory in linux
I have a shell script which needs to be run on paired files (eg file1
and file2
). 我有一个shell脚本,需要在配对文件(例如file1
和file2
)上运行。 For each pair, there should be 5 output files generated in the current directory. 对于每对,在当前目录中应该生成5个输出文件。 How can I run a shell script on multiple paired files in different directories? 如何在不同目录中的多个配对文件上运行Shell脚本?
To be more specific, the structure looks like the following: 更具体地说,该结构如下所示:
pair1: /x/y/z/1/file1 and x/y/z/1/file2
pair2: /x/y/z/2/file1 and x/y/z/2/file2
I want to run the same shell script on multiple pairs like these two. 我想在像这两个这样的多对上运行相同的shell脚本。 The output needs to be saved in the current directory, eg /x/y/z/1/
for pair1
. 需要将输出保存在当前目录中,例如对pair1
/x/y/z/1/
。
Run the script as: 运行脚本为:
myscript /x/y/z/1/file1 /x/y/z/1/file2 /x/y/z/2/file1 /x/y/z/2/file2
The script contains: 该脚本包含:
#!/bin/bash
create_five_files_with_pair() {
cp $1 outfile1
cp $2 outfile2
cat $1 $2 > outfile3
cat $2 $1 > outfile4
paste $1 $2 > outfile5
}
while test $# -gt 1
do
cd $(dirname $1)
create_five_files_with_pair $(basename $1) $(basename $2)
shift
shift
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.