English 中文(简体)
Awk改为一栏,面值
原标题:Awk replace a column with its hash value
  • 时间:2011-11-06 00:32:19
  •  标签:
  • shell
  • sed
  • awk

我怎么能够用 has(如MD5)的厚度取代一栏?

原始档案是多余的,因此我需要真正高效。

最佳回答
问题回答

因此,你并不真的希望用<代码>wk来做到这一点。 公开的高档语言——Perl语、Alfredo语、Ruby语等——将以更简单、更强的方式这样做。 说了这番话后,这样做将奏效。

考虑到这方面的投入:

this is a test

(例如,用四列一行,我们可以将一栏替换成五栏,如:

awk  {
    tmp="echo " $2 " | openssl md5 | cut -f2 -d" ""
tmp | getline cksum
$2=cksum
print
}  < sample 

This relies on GNU awk (you ll probably have this by default on a Linux system), and it uses openssl to generate the md5 checksum. We first build a shell command line in tmp to pass the selected column to the md5 command. Then we pipe the output into the cksum variable, and replace column 2 with the checksum. Given the sample input above, the output of this awk script would be:

this 7e1b6dbfa824d5d114e96981cededd00 a test

This might work using Bash/GNU sed:

<<<"this is a test" sed -r  s/(S+s)(S+)(.*)/echo "1 $(md5sum <<<"2") 3"/e;s/ - // 
this  7e1b6dbfa824d5d114e96981cededd00  a test

或主要的解决办法:

<<<"this is a test" sed -r  h;s/^S+s(S+).*/md5sum <<<"1"/e;G;s/^(S+).*
(S+)sS+s(.*)/2 1 3/ 
this 7e1b6dbfa824d5d114e96981cededd00 a test

替换<代码>is,从上删除。

解释:

首先:确定栏目,将背参考资料作为Bash指挥中的参数使用,然后加以替代和评价,从而进行宇宙变换,以丢失由md5sum指挥部生成的档案说明(在这种情况下,标准投入)。

在第二种情况下:即,类似于先向封闭空间提供方言,然后在评价五舍五入的指挥、将舱载贴到平流空间(md5sum results)和使用替代安排。

你们也可以这样做:

echo "aze qsd wxc" | perl -MDigest::MD5 -ne  print "$1 ".Digest::MD5::md5_hex($2)." $3" if /([^ ]+) ([^ ]+) ([^ ]+)/  
aze 511e33b4b0fe4bf75aa3bbac63311e5a wxc

如果你想要混淆大量数据,则可能比每条线需要立下5立方米的 s子更快。

虽然我没有做任何基准工作,但你在<条码>上<>read>/code>上可能有更多的时间。

投入(cratch001.txt):

foo|bar|foobar|baz|bang|bazbang
baz|bang|bazbang|foo|bar|foobar

改为read:

while IFS="|" read -r one fish twofish red fishy bluefishy; do
  twofish=`echo -n $twofish | md5sum | tr -d "  -"`
  echo "$one|$fish|$twofish|$red|$fishy|$bluefishy"
done < scratch001.txt

产出:

foo|bar|3858f62230ac3c915f300c664312c63f|baz|bang|bazbang
baz|bang|19e737ea1f14d36fc0a85fbe0c3e76f9|foo|bar|foobar




相关问题
KornShell- Creating a fixed width text file

I need to create a simple fixed width text file in KornShell (ksh). My current attempt using printf to pad the string isn t working out very well. What s the shortest, cleanest way to create a fixed ...

unix find command

how to use the find command to find files/directories which are not matching the pattern. for eg: find <some options > -name "dontfile.txt" should give me output of all the find whose file ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

1. 露台式照像

在Windows XP中,没有一时出现指挥时,是否有办法操作一种灰色文字? 我常常需要把“善待”(工作)与“灰色”同起来,即使我的文字没有产出,......

热门标签