#!/bin/bash
Assuming that the file this code is in has the executable attribute, the system will use /bin/bash to execute it.
echo "Enter file name"
read file
Reads the file name into variable 'file'
echo "Enter the number"
read n
Reads the number of lines over which the awk script will find the max.
awk -v count=$n '{k = $1; getline; for (j=1; j<cunt; j++) {if ( $1 > k ) k = $1; getline; } print k}' $file
This is the awk command to do the work.
-v count=$n
Sets the awk variable count to the number of lines to use for the comparison.
'{k = $1; getline; for (j=1; j<cunt; j++) {if ( $1 > k ) k = $1; getline; } print k}'
This is the awk program. It says:
For everyline
set k to the first value of the current input line
---------- Post updated at 10:58 PM ---------- Previous update was at 10:48 PM ----------
#!/bin/bash
Assuming that the file this code is in has the executable attribute, the system will use /bin/bash to execute it.
echo "Enter file name"
read file
Reads the file name into variable 'file'
echo "Enter the number"
read n
Reads the number of lines over which the awk script will find the max.
awk -v count=$n '{k = $1; getline; for (j=1; j<count; j++) {if ( $1 > k ) k = $1; getline; } print k}' $file
This is the awk command to do the work.
-v count=$n
Sets the awk variable count to the number of lines to use for the comparison.
'{k = $1; getline; for (j=1; j<count; j++) {if ( $1 > k ) k = $1; getline; } print k}'
This is the awk program. It says:
For every line
set k to the first value of the current input line
Get the next input line
For j starting at 1, until j = count do the following
If the new value is greater than k, set k to the new higher value
get the next line
End For j loop
Print the high value for the set of lines
End For every line loop
$file
This is the name of the input file.