LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   reading contents of file (https://www.linuxquestions.org/questions/linux-newbie-8/reading-contents-of-file-4175537113/)

lonesoac0 03-18-2015 06:53 AM

reading contents of file
 
Hello all,

I am trying to figure out how to get bash to view for any contents in the "the_difference_between_today_and_yesterday.txt" file and then act if there is anything in the file. I thought i had it, but it is not working like I thought. Any ideas?

Code:

if [ -f final_version_$dater.txt ];
then
        if [ -f final_version_$yester_dater.txt ];
        then
                diff final_version_$dater.txt final_version_$yester_dater.txt | grep "^>" | sed 's/>\ //g' > the_difference_between_today_and_yesterday.txt

                        if grep ^[a-z]* "the_difference_between_today_and_yesterday.txt";
                        then
                                cp the_difference_between_today_and_yesterday.txt /tmp/24hourlemons_table; mysqlimport --user=USERNAME --password=PASSWORD --columns=name,start_date,end_date,link_url,location \
--fields-terminated-by=':' --lines-terminated-by='\n' carshows /tmp/24hourlemons_table; rm final_version_$three_days_later.txt
                        else
                                echo "There were no differences between the two files"; rm final_version_$three_days_later.txt
                        fi
        else
                echo "ERROR! The file of: final_version_$yester_dater.txt does not exist" >> error.log
        fi
fi


pan64 03-18-2015 09:10 AM

I did not follow that script, but grep pattern should be definitely protected, so better to write: grep '^[a-z]*'
Would be nice to specify what do you mean by "it is not working"! What did you expect and also what happened? Do you have any error messages?


All times are GMT -5. The time now is 06:11 AM.