Parse value from output using AWK

I need to parse the value, after the 100th of a second from output, from an FTP get command.

ftp> 8.591220.98disconnect

With assistance from Stack members I've been using the following to obtain the data:

ut1intput=$(awk 'NR==70{for(i=1;i<=NF;i++)if($i=="ftp>")print $(i+1)} filename.txt)

I'm using sed to strip the word "disconnect" from the output, but am perplexed as to how to print only the 100th of a second output, i.e.: 8.591220.98

Is awk the right tools for this task?

I'd appreciate any advice.


To solve just the immediate problem:

If all you need is to extract the number-like token from your input data, you could simply use tr as follows:

tr -C -d '0-9.' <<<'ftp> 8.591220.98disconnect' # -> '8.591220.98'

But it makes more sense to integrate the desired operation into your original awk program, using sub(), as in @Håkon Hægland's answer:

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

The awk command sub(/disconnect/,"", $i) will strip the word disconnect from field number $i. For instance:

echo "8.591220.98disconnect" | awk '{sub(/disconnect/,"", $1)}1'



Need Your Help

Creating WCF Service that returns a MySqlCommand object in it's only method

c# web-services wcf

I created a WCF Service on visual studio 2015 with one method that returns a MySqlCommand. When i try to add a reference of the service on another service i get an error:

XBAP Clear cache from application

wpf caching clear xbap mage

Is there a way to clear the cache from Xbap application instead of running mage or rundll32 from command prompt??