且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

while 循环读取文件速度极慢

更新时间:2023-12-02 19:11:22

  • 您不需要保留迭代器来添加到数组.你可以简单地做 array+=(item)(not array+=item).
  • 获取输入中的列就像使用带有多个目标变量的 read 一样简单.作为奖励,最后一个变量获得第 N 个词和所有后续词.参见 help [r]ead.
    • You don't need to keep an iterator to add to arrays. You can simply do array+=(item) (not array+=item).
    • Getting the columns in the input is as simple as using read with multiple target variables. As a bonus, the last variable gets the Nth word and all subsequent words. See help [r]ead.
    • 这节省了大量的叉子,但我还没有测试它有多快.

      This saves a ton of forks, but I haven't tested how fast it is.

ogl_date=()
[...]
ogl_commands=()

while read -r date1 date2 time server id type pid commands
do
    ogl_date+=("$date1 $date2")
    [...]
    ogl_commands+=("$commands")
done < /tmp/ftp_search.14-12-02