zoukankan      html  css  js  c++  java
  • awk 在文件每行后面增加个时间戳

    需求

    通过执行命令得出一个结果,需要给结果加入时间戳。

    /opt/thomsonreuters/ads/bin/adsmon -print | grep -B1 -A4 -E "position:.*snowballfinance.com" | grep -vE 'channel:|applicationKey:|protocol:' | sed 's//.*//g' | tr -d '[:blank:]' | sed 's/--/#:#/g' | awk -F ':' '{print $2}' | tr '
    ' ' ' | tr '#' '
    '|awk -v trepIp=`ifconfig eth0|sed -n '2p'|cut -d":" -f2|cut -d" " -f1` '{print trepIp"_"$1"_"$2,$3}'|awk '{a[$1]+=$2}END{for (key in a) print key,a[key]}' |sort

    输出结果:

    10.21.254.105_hk-broker-sh_10.21.0.6 8763
    10.21.254.105_hk-pankou-sh_10.21.0.5 8763
    10.21.254.105_hk-stock-sh_10.21.0.1 163
    10.21.254.105_hk-stock-sh_10.21.0.7 3916
    10.21.254.105_hk-stock-sh_10.21.0.8 2757
    10.21.254.105_hk-stock-sh_10.21.0.9 2090
    10.21.254.105_us-futures-sh_10.21.0.3 1
    10.21.254.105_us-futures-sh_10.21.0.6 109
    10.21.254.105_us-option-sh_10.21.0.1 175001
    10.21.254.105_us-option-sh_10.21.0.2 118702
    10.21.254.105_us-option-sh_10.21.0.3 135658
    10.21.254.105_us-option-sh_10.21.0.4 171277
    10.21.254.105_us-stock-sh_10.21.0.5 4572
    10.21.254.105_us-stock-sh_10.21.0.7 8309
    10.21.254.105_us-stock-sh_10.21.0.8 17
    radmin@TREP2# 

    在前面的命令后加管道 和 awk '{ print $0" " strftime("%Y-%m-%d %H:%M:%S",systime())}' 进行添加时间戳

    完整命令如下:

    /opt/thomsonreuters/ads/bin/adsmon -print | grep -B1 -A4 -E "position:.*snowballfinance.com" | grep -vE 'channel:|applicationKey:|protocol:' | sed 's//.*//g' | tr -d '[:blank:]' | sed 's/--/#:#/g' | awk -F ':' '{print $2}' | tr '
    ' ' ' | tr '#' '
    '|awk -v trepIp=`ifconfig eth0|sed -n '2p'|cut -d":" -f2|cut -d" " -f1` '{print trepIp"_"$1"_"$2,$3}'|awk '{a[$1]+=$2}END{for (key in a) print key,a[key]}' |sort |awk '{ print $0" " strftime("%Y-%m-%d %H:%M:%S",systime())}'

    输出结果:

    10.21.254.105_hk-stock-sh_10.21.0.1 0 2020-08-20 17:02:27
    10.21.254.105_us-futures-sh_10.21.0.3 0 2020-08-20 17:02:27
    10.21.254.105_us-futures-sh_10.21.0.6 109 2020-08-20 17:02:27
    10.21.254.105_us-option-sh_10.21.0.1 175001 2020-08-20 17:02:27
    10.21.254.105_us-option-sh_10.21.0.2 118702 2020-08-20 17:02:27
    10.21.254.105_us-option-sh_10.21.0.3 135658 2020-08-20 17:02:27
    10.21.254.105_us-option-sh_10.21.0.4 171277 2020-08-20 17:02:27
    10.21.254.105_us-stock-sh_10.21.0.5 4572 2020-08-20 17:02:27
    10.21.254.105_us-stock-sh_10.21.0.7 8309 2020-08-20 17:02:27
    10.21.254.105_us-stock-sh_10.21.0.8 17 2020-08-20 17:02:27
    也许世上本没有幸运二字,只有那些给自己提出严格的要求,并且以高度自律逼自己完成的人,才能得到别人眼里的心想事成。
  • 相关阅读:
    audio_policy.conf说明(翻译)
    Qt
    linux C
    Linux C
    Linux C
    Qt
    Qt
    JSON
    JSON
    Qt
  • 原文地址:https://www.cnblogs.com/shigozsr/p/13536141.html
Copyright © 2011-2022 走看看