文本操作脚本----shell和python哪个鸡肋?

18 篇文章 1 订阅

1.先看看文本,40多万行的log信息。处理要求:将第6列打印信息tbmt:后面的数值按照十六进制排序

2.shell脚本如下图,40万行文本,脚本没关打印要运行6-8个小时左右才能处理完。

#! /bin/bash

# --------------------------------------------------------------------------------
# File name   : sort_beta.sh
# Date        : 2018/07/28
# Author      : Gick
# Mail        : gickleeeee@gmail.com
# Usage       : Sort the logFile in ascending
# Version     : 1.0
# --------------------------------------------------------------------------------

#################### test weather file exists or not #####################
if test -z "$1"
then
    echo "please input your log_file!"
    exit 0
fi

if test -z "$2"
then
    echo "please input your log_file for storing the fixed data!"
    exit 0
fi

#################### classified according to the length of string of last column #####################
cat $1 | while read line
do
    echo $line > temp.txt
    ColumnData=`awk '{print $6}' ./temp.txt`
    echo $ColumnData
    ColumnData=`echo ${#ColumnData}`
    case $ColumnData in
    6)
        echo "================= SIZE = 6 ===================="
        echo $line >> temp1.txt
        ;;
    7)
        echo "================= SIZE = 7 ===================="
        echo $line >> temp2.txt
        ;;
    8)
        echo "================= SIZE = 8 ===================="
        echo $line >> temp3.txt
        ;;

    9)
        echo "================= SIZE = 6 ===================="
        echo $line >> temp4.txt
        ;;
    esac
done

#################### sort data of different string lengths separately #####################
echo "================= SIZE = 6 ===================="
sort -k 6.6 temp1.txt > $2

echo "================= SIZE = 7 ===================="
sort -k 6.6 temp2.txt >> $2

echo "================= SIZE = 8 ===================="
sort -k 6.6 temp3.txt >> $2

echo "================= SIZE = 9 ===================="
sort -k 6.6 temp4.txt >> $2

#################### remove temporary files #####################
rm temp*


3.再来看看python脚本,运行时间未测,但应该比上面少。别人写的,先mark,回头学习,是时候转python了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值