gpt4 book ai didi

linux - 在整个目录上运行 bash 脚本

转载 作者:太空宇宙 更新时间:2023-11-04 09:25:21 24 4
gpt4 key购买 nike

我有一个 bash 脚本,可以删除用户指定文件的前五行和后九行。我需要它每天在 ~100 个文件上运行,有没有办法对整个目录运行脚本,然后将每个文件输出到具有相同文件名的单独目录?这是我正在使用的脚本。

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

由于文件太多,我将其设置为循环,但这是脚本的核心。

最佳答案

你可以这样做:

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

假设输入目录是~/Documents/Databases/db3/,输出目录是/out/dir/

关于linux - 在整个目录上运行 bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37099036/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com