简体   繁体   English

在整个目录上运行bash脚本

[英]Run a bash script on an entire directory

I have a bash script that removes the first five lines and last nine lines on a user specified file. 我有一个bash脚本,可删除用户指定文件上的前五行和后九行。 I need it to run on ~100 files a day, is there any way to run the script against the entire directory and then output every file to a separate directory with the same file name? 我需要它每天运行约100个文件,是否有任何方法可以对整个目录运行脚本,然后将每个文件输出到具有相同文件名的单独目录中? Here is the script I am using. 这是我正在使用的脚本。

read -e file
$file | sed '1,7d' | head -n -9 > ~/Documents/Databases/db3/$file
rm $file

I set it up to loop because of so many files but that is the core of the script. 由于文件太多,我将其设置为循环,但这是脚本的核心。

You can do: 你可以做:

for file in ~/Documents/Databases/db3/*; do
    [ -f "$file" ] && sed '1,7d' "$file" | head -n -9 > /out/dir/"${file##*/}"
done

Assuming the input directory is ~/Documents/Databases/db3/ and the output directory is /out/dir/ . 假设输入目录为~/Documents/Databases/db3/ ,输出目录为/out/dir/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM