[英]How to Replace Names in Column of a Text File, Using a Conversion Present in Another Text File With Bash
[英]Printing a column to a text using bash
我有一个Shell脚本将一列打印到文本文件:
#!/bin/bash
for i in `seq 1 1 174492`;
do
for j in `seq 0 100 14000`;
do
echo "$j" >> "depth"
done
done
但是该程序花费的时间太长。 有一个更好的方法吗?
使用内置的括号扩展而不是调用seq
,并重定向整个外部循环,而不是每次内部循环迭代都打开和关闭文件一次:
for i in {1..174492}
do
for j in {0..14000..100}
do
echo "$j"
done
done >> "depth"
现在您的开销就是循环本身,因此,如果仍然不够快,请使用更快的语言:
awk 'BEGIN {
for (i = 1; i <= 174492; ++i)
for (j = 0; j <= 14000; j += 100) print j
}' >> depth
我在系统上进行了测试,耗时8秒,而Shell循环耗时2分钟。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.