Instead of writing to two different files I’d like to be able to write the information to one file and then be able to just read from this one file to get the information that I need later. Is there a way that I can go about doing this? Currently I’m using the “Cat” command to read the contents of these files.
Is it possible to place this information on my logfile in a specific location, say behind a variable name?
Like this:
Monthly date= "place info here"
Weekly date = "place info here"
Could I then use the “grep” and the “cut” command to search for either the “Monthly date” or the “Weekly date” and pull that information off of the file?
Sure, but it would make life simpler if you wrote it out in a form that is easy to parse later. Lots of possibilities:
echo “Monthly_date $NEWDATE” > logfile
Then later:
DATE=grep Monthly_date logfile | cut -d ' ' -f 2-
Notice the use of _ to make Monthy_date one field, and a single space as the field delimiter. Or you could do the grep and cut in one awk command. Or a Perl script.
Hi
You also might want to have a look as using logger (see man logger).
Also use less or more commands if you wish to browse, if you use a /
then add a search string <enter> and the just using /<enter> you can
search for all occurrences.
–
Cheers Malcolm °¿° (Linux Counter #276890)
openSUSE 11.0 x86 Kernel 2.6.25.18-0.2-default
up 2 days 2:44, 3 users, load average: 0.23, 0.07, 0.03
GPU GeForce 6600 TE/6200 TE - Driver Version: 177.80
Ok, I tried using the “echo” command as you suggested and it’s getting me closer to what I want:), but I’m not quite there yet.
Doing it this way always overwrites what is on the logfile. That’s a problem because I’m writing data to it at different times and I don’t want to remove the existing data that was previously written there. I just want to update what’s there.
For example, I will always want to have “Monthly_date” and “Daily_date” located on this logfile. There are times when I may only be writing the “Daily_date” to this logfile and I don’t want to remove the “Monthly_date” information.
Well then it’s not a logfile. Remember, a captain when writing a log never deletes entries but keeps appending to the log. While you could append instead of overwrite, using >> instead of >, in this situation you really should write this info to a separate file. Files are cheap to create and use in Linux. So:
echo "$NEWDATE" > Monthly_date
Then you don’t need to do anything special to retrieve the date. Just
DATE=`cat Monthly_date`
Of course you can continue to use $NEWDATE for timestamping entries in the logfile.
Yeah, I guess you’re right, it’s not a log file. I just needed a place to store information for when I run the script the next time. The only way that I could think of how to do this was to write this information to a file. I just thought it would be cleaner to write all my information to one file and then just retrieve it when I need to.