AWK脚本。寻找优化的例子

时间:2014-04-02 16:42:39

标签: sed awk

我借用并编写了以下代码来输出断开连接时间。一切运作良好,但我很好奇我如何收紧/缩短代码。如果有人想要享受一些乐趣,那么我很乐意看到可以做些什么。对我来说是一个学习课程。

提前干杯。

输入:

ftp> !:--- FTP commands below here ---
ftp> lcd C:\Utilities\Performance_Testing\
\Utilities\Performance_Testing\: File not found 
Verbose mode On .
ftp> verbose
binary
200 Switching to Binary mode.
ftp> put "test_file_5M.bin"
200 PORT command successful.
150 Ok to send data.
226 File receive OK.
ftp: 5242880 bytes sent in Seconds Kbytes/sec.
ftp> 44.81117.00disconnect
221 Goodbye.
ftp> bye 

代码:

#Obtain UT external put value.
ut1intput=$(awk '
  NR==70 {
    for(i=1;i<=NF;i++) { 
      if($i=="ftp>") {
        sub(/disconnect/, "", $(i+1));
        print $(i+1)
      }
    }
  }' filename.txt)

utintputvalue=`echo $ut1intput | awk -F. '{print $2"."$3}'| sed  's/^..//'`

输出:

UT external put value is 1220.98

1 个答案:

答案 0 :(得分:0)

根据您在评论中说出的所需的样本输入和所需的输出:

$ sed -n 's/^.*\(......\)disconnect/UT external put value is \1/p' file
UT external put value is 117.00