我在我的bash腳本中使用這段代碼來讀取包含多個十六進制字符串的文件,進行一些替換,然後將其寫入新的文件。約300 Mb大約需要30分鐘。
我想知道如果這可以做得更快?這可以做得更快(讀取文件,替代[sed],寫入新文件)
sed 's,[0-9A-Z]\{2\},\\\\x&,g' ${in_file} | while read line; do
printf "%b" ${line} >> ${out_file}
printf '\000\000' >> ${out_file}
done
更新:
我做了一些測試,並得到了以下結果:
獲獎者是:
sed 's,[0-9A-Z]\{2\},\\\\x&,g' ${in_file} | while read line; do
printf "%b" ${line} >> ${out_file}
printf '\000\000' >> ${out_file}
done
真正44m27.021s
ü SER 29m17.640s
SYS 15m1.070s
sed 's,[0-9A-Z]\{2\},\\\\x&,g' ${in_file} | while read line; do
printf '%b\000\000' ${line}
done >> ${out_file}
真正18m50.288s
用戶8m46.400s
SYS 10m10.170s
export LANG=C
sed 's/$/0000/' ${in_file} | xxd -r -ps >> ${out_file}
真正0m31.528s
用戶0m1 .850s
sys 0m29.450s
顯示輸入文件的例子,你的輸出格式 – ghostdog74 2010-09-12 10:49:43
招數調用之前運行此更改爲快速C語言環境:export LANG = C – LatinSuD 2010-09-12 11:00:57
@LatinSuD。不明白你的意思。 – 2010-09-12 11:14:03