linux: check if x is greater than y and display them

August 23, 2012 at 23:26:36
Specs: Linux
Hi Guru,
I have a source file that contains the following:
apple:50
banana:100
orange:88
cherry:91

I'd like to find out which fruit has greater than 90 and show them like the following result:
banana:100
cherry:91

Is there any way to do this using shell scripting, such as bash, ksh.....??

Any help will be much appreciated


See More: linux: check if x is greater than y and display them

Report •

#1
August 26, 2012 at 07:31:23
I'll get you started with a bash script that parses each line into 2 fields:


#!/bin/bash

# split each line into 2 fields:
while IFS=":" read f1 f2
do
echo $f2
done < sourcefile.txt
# end script
</per>

I'll leave the if statement to you.


Report •
Related Solutions


Ask Question