Question: I have a question. Assuming I dump a file and do a grep for foo and comes out the result like this:

```

Foo-bar-120:'foo name 1'
Foo-bar-130:'foo name 2'
Foo-bar-1222:'foo name 3'

```

Etc.

All I want is trying to extract the foo name with largest number. For instance in this case, largest number is 1222 and the result I expect is `foo name 3`

Is there a easy way using awk and sed to achieve this? Rather than pull the number out line by line and loop through to find the largest number?

Answer: 
Here's how I would do it. I just tested this in Cygwin. Hopefully it works under Linux as well. Put this into a file, such as `mycommand`:

```
#!/usr/bin/awk -f

BEGIN {
        FS="-";
        max = 0;
        maxString = "";
}

{
        num = $3 + 0; # convert string to int
        if (num > max) {
                max = num;
                split($3, arr, "'");
                maxString = arr[2];
        }
}

END {
        print maxString;
}

```

Then make the file executable (`chmod 755 mycommand`). Now you can pipe whatever you want through it by typing, for example, `cat somefile | ./mycommand`.
is this ok for you?

```
awk -F'[:-]' '{n=$(NF-1);if(n>m){v=$NF;m=n}}END{print v}'

```

with your data:

```
kent$  echo "Foo-bar-120:’foo name 1’
Foo-bar-130:’foo name 2’
Foo-bar-1222:’foo name 3’"|awk -F'[:-]' '{n=$(NF-1);if(n>m){v=$NF;m=n}}END{print v}'
’foo name 3’

```

P.S. I like the Field separator `[:-]`