LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-18-2015, 06:53 AM   #1
lonesoac0
Member
 
Registered: Jan 2010
Distribution: Ubuntu
Posts: 94

Rep: Reputation: 4
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

Last edited by lonesoac0; 03-18-2015 at 06:53 AM. Reason: ooops
 
Old 03-18-2015, 09:10 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,645

Rep: Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501
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?
 
  


Reply

Tags
bash, read


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Diff File contents while reading using "cat" and "more" maitree@123 AIX 3 07-31-2014 08:59 AM
Reading contents of a specific block of a file Bhupendra Singh Linux - Newbie 2 06-21-2013 08:56 PM
Create a Multiple files by reading a input file and changing the contents bhargavkr Linux - Newbie 4 09-17-2009 12:37 AM
Reading the Contents of a Dump Tape kaplan71 Linux - General 2 11-08-2006 02:34 PM
Reading screen contents dogpatch Programming 2 11-29-2005 03:41 PM


All times are GMT -5. The time now is 05:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration