散列文本文件中的每一行 [英] hash each line in text file

查看:117
本文介绍了散列文本文件中的每一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写一个小脚本,这将打开一个文本文件,并给我的每一行文本的MD5哈希值。比如我有一个文件:

I'm trying to write a little script which will open a text file and give me an md5 hash for each line of text. For example I have a file with:

123
213
312

我想输出是:

ba1f2511fc30423bdbb183fe33f3dd0f
6f36dfd82a1b64f668d9957ad81199ff
390d29f732f024a4ebd58645781dfa5a

我试图做这部分在bash这将读取每一行:

I'm trying to do this part in bash which will read each line:

#!/bin/bash
#read.file.line.by.line.sh

while read line
do
echo $line
done

后来我做的:

$ more 123.txt | ./read.line.by.line.sh | md5sum | cut -d '  ' -f 1

但我在这里失去了一些东西,不工作:(

but I'm missing something here, does not work :(

也许还有一个更简单的方法...

Maybe there is an easier way...

推荐答案

快到了,试试这个:

while read line; do echo -n $line|md5; done < 123.txt

除非你也想在哈希每行换行字符,你应该包括-n选项。

Unless you also want to hash the newline character in every line you should include the '-n' option.

在一个脚本:

#!/bin/bash
while read line; do echo -n $line|md5; done < $1

这篇关于散列文本文件中的每一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆