QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 889|回复: 1

script程序运行速度问题

[复制链接]
发表于 2006-2-8 11:37:47 | 显示全部楼层 |阅读模式
我有一个程序,需要读取一个文件中的每行,然后进行分类操作,但是程序运行速度很慢,不知道怎样来提高一下运行速度,肯求各位达人宝贵建议,程序如下:
SEQ=0
while read "LINE"
do

  PAGE_CHECK=`echo "$LINE" | cut -c 1-5`
  if [ "$PAGE_CHECK" = "PAGNO" ];then

    PAGE_NO=`echo "$LINE" | cut -c 11`

    PAGE_1_CHECK=`echo "$LINE" | cut -c 1-6`
    if [ "$PAGE_1_CHECK" = "PAGNO1" ];then

       SEQ=$(($SEQ + 1 ))
    fi

    if [ "$SEQ" = "4" ];then
      SEQ=1
    fi

    if [ "$SEQ" = "1"  ];then
       if [ "$PAGE_NO" = "1" ];then
          echo "om987" >> output.DAT
         
       elif [ "$PAGE_NO" = "3" ];then
          echo "om988" >> output.DAT

       elif [ "$PAGE_NO" = "5" ];then
          echo "om989" >> output.DAT

       elif [ "$PAGE_NO" = "2" ];then
          echo "$LINE" >> output.DAT
       elif [ "$PAGE_NO" = "4" ];then
          echo "$LINE" >> output.DAT
       elif [ "$PAGE_NO" = "6" ];then
          echo "$LINE" >> output.DAT
       fi
     fi
    if [ "$SEQ" = "2" ];then
        if [ "$PAGE_NO" = "1" ];then
          echo "om985" >> output.DAT

       elif [ "$PAGE_NO" = "3" ];then
         echo "om984" >> output.DAT

       elif [ "$PAGE_NO" = "5" ];then
          echo "om989" >> output.DAT

       elif [ "$PAGE_NO" = "2" ];then
          echo "$LINE" >> output.DAT
       elif [ "$PAGE_NO" = "4" ];then
          echo "$LINE" >> output.DAT
       elif [ "$PAGE_NO" = "6" ];then
          echo "$LINE" >> output.DAT
        fi
       fi
    if [ "$SEQ" = "3" ];then
        if [ "$PAGE_NO" = "1" ];then
          echo "om980" >> output.DAT
       elif [ "$PAGE_NO" = "3" ];then
          echo "om981" >> output.DAT

       elif [ "$PAGE_NO" = "5" ];then
          echo "om982" >> output.DAT

       elif [ "$PAGE_NO" = "2" ];then
          echo "$LINE" >> output.DAT
       elif [ "$PAGE_NO" = "4" ];then
          echo "$LINE" >> output.DAT
       elif [ "$PAGE_NO" = "6" ];then
          echo "$LINE" >> output.DAT
        fi
      fi

  else
  echo "$LINE" >> output.DAT
  fi
done < input.DAT
exit 0
 楼主| 发表于 2006-2-8 14:02:33 | 显示全部楼层
ps:这个程序顺序读取input.DAT中的每行字符串,然后查找“page_no”"page_no1"字段,如果有的话,进行插入output.DAT文件的一些操作,大部分时间消耗在顺序读取input.DAT中每行字符串的操作上了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-2 12:33 , Processed in 0.039204 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表