【发布时间】:2013-08-21 14:02:41
【问题描述】:
我正在尝试制作一个脚本,允许我在对这些文件的特定列执行命令时逐行读取目录中的所有文件。我正在处理的文件是 .txt 文件,其值由逗号分隔。我可以通过将文本文件输入到脚本然后输出值而不是多个文件来使用单个文件执行代码,这是我的目标。我希望按照它们在目录中的顺序读取文件。这是我目前所拥有的。
directory=$(/dos2unix/*.txt)
file=$(*.txt")
IFS=","
for "$file" in "$directory";
do
while read -ra line;
do
if [ "${line[1]}" != "" ]; then
echo -n "${line[*]}, Hash Value:"; echo "${line[1]}" | openssl dgst -sha1 | sed 's/^.* //'
else
if [ "${line[1]}" == "" ]; then
echo "${line[*]}, Hash Value:None";
fi
fi
done
done
我遇到的一些错误是:
$ ./orange2.sh
/dos2unix/test1.txt: line 1: hello: command not found
/dos2unix/test1.txt: line 2: goodbye: command not found
/dos2unix/test1.txt: line 4: last: command not found
./orange2.sh: line 28: unexpected EOF while looking for matching `"'
./orange2.sh: line 33: syntax error: unexpected end of file
有任何提示、建议或示例吗?
谢谢大家
更新
我还希望最终复制所有文件以包含您在第一个 if 语句中看到的命令,所以我想 a.) 将我的文件分开 b.) 创建一个包含更新的副本价值。
【问题讨论】:
-
google for
find -type f -execdir cmd {} \;
标签: bash shell scripting directory