5.3 Alternatives

There are many alternatives that can be found with a search engine. However, they are usually more complicated than the “simple algorithm” we used above. Incidently I also found a few online answers that did not give the correct answer. Hence testing results is essential.

Here are 2 mini “programs” found online13 that provided the correct answer with a file (x.) containing only the matrix of numbers (i.e. removed first line and last column.)

# Prepare x.:  remove 1rst line and last column
sed 1d spike_diff.dist | awk '{$NF=""; print}'  > x.

Awk version:

awk '$1 > m || NR == 1 { m = $1 } END { print m }' x.

Perl version:

perl -MList::Util=max -alne '$tmp = max @F; $max = $tmp if $max < $tmp; END { print $max }' x.

Note: The commands to prepare x. and the perl or awk commands could all be stringed together with the pipe symbol to create a single pipeline. For example for the awk version we would string commands together as:

sed 1d spike_diff.dist | awk '{$NF=""; print}' | awk '$1 > m || NR == 1 { m = $1 } END { print m }'

Finding the simplest and least specific solution is usually the best answer as it can be used in multiple settings. The simplest solution “version 3” above is probably the best answer to finding the largest number.