How can I grep asterisk *
inside of a text file?
Here is my code :
if grep -F "\#$minute $hour $date $month $day $cr_user $comm" filecron; then
echo "$minute $hour $date $month $day $cr_user $comm" > /dev/null 2>&1
echo "data exist"
elif [[ -z $minute || -z $hour ]]; then
echo "#$minute $hour $date $month $day $cr_user $comm" > /dev/null 2>&1
echo "nothing to input"
echo "" >> filecron
elif [[ $stat == "inactive" ]]; then
echo "\#$minute $hour $date $month $day $cr_user $comm" >> filecron
echo "input data inactive to filecron"
else
echo "$minute $hour $date $month $day $cron_user $comm" >> filecron
echo "input data active to filecron"
fi
Here is filecron contain
#30 07 03 09 RAB root bash /media/data/once.sh > /dev/null 2>&1
#* * * * * root bash /media/data/looping.sh > /dev/null 2>&1
#56 * * * * root bash /media/data/minutely.sh /dev/null 2>&1
#43 * * * * root bash /media/data/hourly.sh > /dev/null 2>&1
#54 11 * * * root bash /media/data/daily.sh /dev/null 2>&1
#00 12 * * RAB root bash /media/data/weekly.sh > /dev/null 2>&1
#30 20 15 * * root bash /media/data/monthly.sh > /dev/null 2>&1
#45 21 01 09 * root bash /media/data/yearly > /dev/null 2>&1
#15 16 31 08 MIN root bash /media/data/other.sh > /dev/null 2>&1
#30 07 * * * root bash /media/data/daily2.sh > /dev/null 2>&1
#30 10 * * * root bash /media/data/daily3.sh > /dev/null 2>&1
#45 17 17 * * root bash /media/data/monthly2.sh > /dev/null 2>&1
#00 18 * * SAB root bash /media/data/weekly2.sh > /dev/null 2>&1
#30 07 03 09 RAB root bash /media/data/once.sh > /dev/null 2>&1
#* * * * * root bash /media/data/looping.sh > /dev/null 2>&1
#56 * * * * root bash /media/data/minutely.sh /dev/null 2>&1
#43 * * * * root bash /media/data/hourly.sh > /dev/null 2>&1
But grep
doesn't work if $minute
or $hour
or $month
or $day
or $date
is *
So, how do I do this?
If you don't have any regular expression patterns, and just want to match the string exactly, use the -F
option to grep
(or the older fgrep
command):
if grep -F "#$minute $hour $date $month $day $cr_user $comm" filecron; then
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With