hiipm 发表于 2006-2-8 11:37:47

script程序运行速度问题

我有一个程序,需要读取一个文件中的每行,然后进行分类操作,但是程序运行速度很慢,不知道怎样来提高一下运行速度,肯求各位达人宝贵建议,程序如下:
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

hiipm 发表于 2006-2-8 14:02:33

ps:这个程序顺序读取input.DAT中的每行字符串,然后查找“page_no”"page_no1"字段,如果有的话,进行插入output.DAT文件的一些操作,大部分时间消耗在顺序读取input.DAT中每行字符串的操作上了
页: [1]
查看完整版本: script程序运行速度问题