我正在尝试将纯文本密码添加到导出的用户表中的相应行。我有两个文件:
用户表
barry hash1
fred hash2
mary hash3
rich hash2
crackpasstable
ptpass1 hash1
ptpass2 hash2
我希望输出看起来像:
combintedtable
barry hash1 ptpass1
fred hash2 ptpass2
mary hash3
rich hash2 ptpass2
我已根据我找到的另一个条目尝试了以下代码,但这只会打印出匹配的行,而不是所有行:
$ awk 'NR==FNR{a[$2]=$0; next} a[$2]>0{print a[$2],$1}' usertable crackpasstable > combinedtable
我想尝试打印出usertable中的所有行(希望按原始顺序),如果我能够破解它们,只需在新列中添加匹配的密码。
谢谢
答案 0 :(得分:0)
<强> pr.awk:强>
# Usage:
# awk -f pr.awk crackpasstable usertable > combintedtable
BEGIN {
ct = ARGV[1]
ARGV[1] = "" # read ARGV[1] file implicitly, ARGV[2] file
# explicitly
while (getline < ct > 0) {
p = $1
h = $2
phash[h] = p
}
}
{
h = $2
if (h in phash)
print $0 " " phash[h]
else
print
}
答案 1 :(得分:0)
crackpasstable
,然后扫描usertable
并添加已加载文件的传递
# read in the first file
FNR == NR {
hashes [$2] = $1 # hopefully, there are no repeating hash values
next
}
# scan all other files
$2 in hashes {
$0 = $0 "\t" hashes[$2]
}
1 # or {print} if you prefer to be explicit
用法:
> ThisScript crackpasstable usertable
答案 2 :(得分:0)
或
awk 'NR==FNR {a[$2]=$1;next} {print ($2 in a) ? $0"\t"a[$2] : $0}' crackpasstable usertable