如何更改 md5sum 命令输出的分隔符
我的代码如下所示:
for i in `find` ;
do
if [ -f $i ]; then
if [ "$i" != "./ex.sh" ]; then
md5sum $i >> checksums.txt;
fi
fi
done
问题是我想稍后在文件上使用 awk 并带有“|”作为分隔符。但是我不知道如何用“|”附加到文件 checksums.txt在 md5sum 和 $i 之间。 谢谢
My code looks like this:
for i in `find` ;
do
if [ -f $i ]; then
if [ "$i" != "./ex.sh" ]; then
md5sum $i >> checksums.txt;
fi
fi
done
The problem is I want to use awk on the file later with a "|" as the delimiter. However I don't know how to append to file checksums.txt with a "|" between the md5sum and the $i.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用这个:
Use this:
包括这个问题,我已经阅读了至少3个关于同一问题的问题。我猜你想找到某个目录下的所有重复文件,对吧?
那么你可以尝试下面的一个行,它将保存你以后的循环或双循环和 awk 处理:
它将列出重复的 md5sum 和文件名。
如果我的猜测是错误的,请忽略我的回答。
Including this question, I've read at least 3 questions from you regarding the same problem. I guess you want to find all duplicated files under some directory, right?
then you can try the one liner below, it would save your later looping or double looping and awk processing:
it will list duplicated md5sum and file names.
if my guessing was wrong, just ignore my answer.
md5sum
(至少是 GNU coreutils 中的版本)不提供用于控制输出格式的选项。您应该更改 awk 脚本,将字符 0...15 视为 md5sum,并将行末尾的字符 18 视为文件名。如果您确实需要特定格式,则应该解析 md5sum 的输出。例如:此外,您应该将
md5sum
的参数括在引号中 (md5sum "$i"
)。正如所写,如果有任何文件名包含空格或特殊字符,脚本将失败。md5sum
(at least the version in GNU coreutils) doesn't provide options for controlling the output format. You should change your awk script to treat the characters 0...15 as the md5sum, and characters 18 to the end of the line as the filename. If you really need the particular format, you should parse the output ofmd5sum
. For example:Also, you should be enclosing the argument to
md5sum
in quotes (md5sum "$i"
). As written, the script will fail if there are any filenames containing spaces or special characters.