HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Extracting performance statistics from FTP session transcript

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
ftpstatisticsperformanceextractingsessionfromtranscript

Problem

I've borrowed and written the following code to output the disconnect time. All works well but I'm curious as to how I could tighten/ shorten the code. If anyone feels like having some fun then I'd love to see what can be done. Be a learning lesson for me.

Excerpt of input:

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


Code:

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

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


Output:

utintputvalue is 117.00

Solution

Assuming the "Output" section is stored in "filename.txt", and assuming you have GNU tools:

grep -oP '(?<=\.\d\d)\d+\.\d\d(?=disconnect)' filename.txt


That's a perl regex meaning: prececeded dot and two digits, find some digits, a dot and two digits, followed by "disconnect". grep's -o option means "output only the matched text".

Code Snippets

grep -oP '(?<=\.\d\d)\d+\.\d\d(?=disconnect)' filename.txt

Context

StackExchange Code Review Q#46074, answer score: 5

Revisions (0)

No revisions yet.