如何获取文件名的md5sum值

时间:2019-01-31 21:02:53

标签: awk md5sum

我可以使用awk分割非常大的文件。

awk -F, '{print $0 >> ($3"|"substr($1,1,10)"|"$6"|"$4"|"$5".csv")}' /largefile.csv

以类似的名称创建文件

SPX|2018-03-20|C|2018-04-20|1000.csv

但是我真正想要的是md5sum 'SPX|2018-03-20|C|2018-04-20|1000'得到类似e560d68e36bbc627efabcdee5ac328b9的东西,并最终格式化为此

E/56/0d68E36BbBC627EFABCDEe5AC328B9.csv

我已经测试了这一行,可以正确打印cmd

awk -F, '{key=$3"|"substr($1,1,10)"|"$6"|"$4"|"$5".csv"; cmd="md5sum \47"key"\47"; print cmd}' /largefile.csv

但是我只是无法获取hashName ...我已经尝试过了这一行,但是它给了我大文件内容。

awk -F, '{key=$3"|"substr($1,1,10)"|"$6"|"$4"|"$5".csv"; cmd="md5sum \47"key"\47" cmd | getline; hashName=$0; print hashName}'

如何获取HashName,如果您不介意插入两个'/',例如E/56/0d68E36BbBC627EFABCDEe5AC328B9.csv

谢谢!

这是我的Largefile.csv中的5条示例行

2018-03-20 09:30:00,9327,SPX,2018-04-20,1000,C,E,SPX   180420C01000000,1712.7,1724.2,2018-03-19 16:02:00,2018-03-19 16:02:00,5,4,W,W,0,1.6005,2712.9199,0.98902,0.00002,-0.417058,0.20079,0.8415,-1,,2018-03-20 09:26:00,2018-03-20 09:30:00
2018-03-20 09:31:00,9327,SPX,2018-04-20,1000,C,E,SPX   180420C01000000,1711.6,1723.1,2018-03-20 09:30:11,2018-03-20 09:30:11,50,49,W,W,0,1.0127,2717.1299,0.99819,0.000001,0,0.00611,0.84745,-1,,2018-03-20 09:30:37,2018-03-20 09:31:00
2018-03-20 09:32:00,9327,SPX,2018-04-20,1000,C,E,SPX   180420C01000000,1714.6,1726.1,2018-03-20 09:31:29,2018-03-20 09:31:29,50,49,W,W,0,0.9711,2720.52,0.99828,0.000001,0,0.00365,0.84765,-1,,2018-03-20 09:31:42,2018-03-20 09:32:00
2018-03-20 09:33:00,9327,SPX,2018-04-20,1000,C,E,SPX   180420C01000000,1713.7,1725.2,2018-03-20 09:32:03,2018-03-20 09:32:03,50,49,W,W,0,0.9674,2720.23,0.99829,0.000001,0,0.00348,0.84764,-1,,2018-03-20 09:32:46,2018-03-20 09:33:00
2018-03-20 09:34:00,9327,SPX,2018-04-20,1000,C,E,SPX   180420C01000000,1713.1,1724.3,2018-03-20 09:33:23,2018-03-20 09:33:23,50,49,W,W,0,0.9494,2719.75,0.99831,0,0,0.00274,0.84769,-1,,2018-03-20 09:33:39,2018-03-20 09:34:00

1 个答案:

答案 0 :(得分:0)

像这样吗?

$ seq 3 | awk '{key=$0   # use your key here
                cmd="echo " key "| md5sum"; 
                cmd | getline line; 
                sub(/ .*/,"",line); 
                print (substr(line,1,1) "/" substr(line,2,2) "/" substr(line,3)".csv")}'

b/02/26324c6904b2a9cb4b88d6d61c81d1.csv
2/6a/ab0db90d72e28ad0ba1e22ee510510.csv
6/d7/7fce9fee471194aa8b5b6e47267f03.csv

但是,要将它们用作文件路径,您需要分别创建子目录。