How to match a content from a file using if in bash
by blason from LinuxQuestions.org on (#5BC1P)
Hi Folks,
Would really appreciate if someone can give any hints or help me here?
Here is my function which is converting IP addresses into a statement with
Code:function convert {
while read ip; do
if [ ! -z "$ip" ] && [ ${ip:0:1} != "#" ]
then
echo "add -a d -l r -t $SAMP_RULE_TIMEOUT -c $SAMP_COMMENT quota service any source range:$ip pkt-rate 0"
fi
done
}Here is the usage of convert function
Code:curl --user $_USER:$_PASS -s --retry 10 --retry-delay 60 $url | dos2unix | grep -vE '^$'| convert > $cache_file_nameNow original file Would contain
100.200.100.200
20.30.40.50
40.50.60.70
150.150.150.0/24
AS548221
cc:RU
cc:VN
However I wanted to use same function for matching contents from file when has "/" OR "^AS" OR "cc:"; so that whenever / OR AS or cc is matched appropriate statements will be used.
I am able to convert the IP addresses to a proper statement however stuck how do I match
Code:if $ip == "/"
then
echo "blah blah"
elif $ip == "^AS"
then "blah blah"
else
exit 1
fi


Would really appreciate if someone can give any hints or help me here?
Here is my function which is converting IP addresses into a statement with
Code:function convert {
while read ip; do
if [ ! -z "$ip" ] && [ ${ip:0:1} != "#" ]
then
echo "add -a d -l r -t $SAMP_RULE_TIMEOUT -c $SAMP_COMMENT quota service any source range:$ip pkt-rate 0"
fi
done
}Here is the usage of convert function
Code:curl --user $_USER:$_PASS -s --retry 10 --retry-delay 60 $url | dos2unix | grep -vE '^$'| convert > $cache_file_nameNow original file Would contain
100.200.100.200
20.30.40.50
40.50.60.70
150.150.150.0/24
AS548221
cc:RU
cc:VN
However I wanted to use same function for matching contents from file when has "/" OR "^AS" OR "cc:"; so that whenever / OR AS or cc is matched appropriate statements will be used.
I am able to convert the IP addresses to a proper statement however stuck how do I match
Code:if $ip == "/"
then
echo "blah blah"
elif $ip == "^AS"
then "blah blah"
else
exit 1
fi