I have a file with numbers separated by ,(comma). In between it also contains a number range like 300-400. Say for example I have a text file, namely testme.txt which looks like,
200,300,234,340-350,400,360,333-339
409-420
4444-31231231
348
I want to find out whether number 348 is present or not. 348 is present in 2 places:
- 340-350
 - In last line.
 
How to find it?. I tried using regex in sed,awk, but I am not able to completely write the script to capture the number range. Is there any other way to find it?
UPDATE: Found 1 brute force solution & it's working only for range.
count=0;
num1=348;
for i in `sed 's/\([0-9]\+\-[0-9]\+\)/:&:/g' testme.txt  | 
    awk -F: '{ for(i=1; i<=NF; i++) if($i ~/[0-9]+-[0-9]+/){print $i} }'`;      
do 
    lh=`echo $i | awk -F\- '{print $1}'`; 
    rh=`echo $i | awk -F\- '{print $2}'`;  
    if [ $lh -le $num1 -a $rh -ge $num1 ]; 
    then  
        count=`expr $count + 1`; 
    fi; 
done
echo $count;
    
400;360or400,360?FSyou can split at both space and comma).