I think you're looking for a shell script that can take two arguments - a filename and a reference number. Let's call the file F and the reference number R.
If file F contains a line of the form
test : N where N is a number, you want to perform some action if N > R and an alternative action if N <= R.
If I have understood the problem correctly, this shell script should do the trick:
matching=$(grep "test" $1 | head -n 1 | cut -d ":" -f 2)
if [ -z $matching ]; then
echo "no matching lines!" >&2
trimmed=$(echo $matching | xargs)
if [ $trimmed -gt $2 ]; then
echo "less than or equal to"
Suppose you save this in a file called
Then you can run
./myscript input.txt 100 and if
input.txt contains a line like
test : 52 you'll see
less than or equal to echoed to standard output.
Update: The asker lists an alternative scenario in the comments where there may be multiple lines matching
test : n in a file. The largest value associated with
test needs to be selected and compared with the reference. Just modify the first line in the script:
matching=$(grep "test" $1 | cut -d ":" -f 2 | sort -gr | head -n 1)
The subsequent lines are the same as before.