Parsing Date to a file name


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Parsing Date to a file name
# 1  
Old 08-18-2008
Parsing Date to a file name

Hi All

There is a file "apple_2008-08-15.log".

I have to use grep on this file to collect my test log. There are 45 such files. Is there a command that I can use to dynamically substitute the daily date as part of the file name? As of now Iam renaming the file to the new date and running my shell script. Please help me.

Also please let me know how to a create folder with the current date as its name dynamically.
# 2  
Old 08-18-2008
for your first part - why not do a

Code:
for i in $(ls)
do
...
done

loop, and for your 2nd question, the following should set you on the right path:

Code:
#  date +%Y-%m-%d
2008-08-18

# 3  
Old 08-18-2008
That's a Useless Use of ls right there.

Code:
for i in *
do
  ...
done

# 4  
Old 08-18-2008
Hi All

Thanks for your replies...

But what Iam looking for is something like

cat apple_<command to substitute the current date>.log
# 5  
Old 08-18-2008
:-)

ok - what I should have said was

Code:
for i in $(ls apple*.log)

bu I was being lazy ;-)
# 6  
Old 08-18-2008
That's still a Useless Use of ls

Code:
for i in apple*.log

# 7  
Old 08-18-2008
Hi All

Thanks for all your replies..

The following satisfied me with the output.

cat apple_`date +%Y-%m-%d`.log


Thanks...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Really need some help with Parsing files by date

Hi, I am new to Unix and need some help with a problem I have. I have been asked to ftp a file(s) from a directory to another system. I need to be able to allow the current days file to build and only send any other file across that is in the directory. I need a peice of code that will read... (3 Replies)
Discussion started by: darrenwg99
3 Replies

2. Shell Programming and Scripting

New to UNIX ... Date parsing

Hi ... extremely new to Unix scripting ... I have to get a date field from mm/dd/yyyy to yyyy/mm/dd format ... I have a variable that I want parsed. I don't seem to be doing it right?? Thanks. (19 Replies)
Discussion started by: MJKeeble
19 Replies

3. UNIX for Dummies Questions & Answers

Parsing file, reading each line to variable, evaluating date/time stamp of each line

So, the beginning of my script will cat & grep a file with the output directed to a new file. The data I have in this file needs to be parsed, read and evaluated. Basically, I need to identify the latest date/time stamp and then calculate whether or not it is within 15 minutes of the current... (1 Reply)
Discussion started by: hynesward
1 Replies

4. Shell Programming and Scripting

Parsing the date output

Hi fellows, I need to define a notification for SSL certificate expiration. My Command output is below: (this is the "Expiration Date") Tue Mar 15 09:30:01 2012 So, at 15th Feb (1 month before the expiration), a notification has to be triggered by a script or sth else. How can i set an... (5 Replies)
Discussion started by: oduth
5 Replies

5. Shell Programming and Scripting

Parsing Log File Based on Date & Error

I'm still up trying to figure this out and it is driving me nuts. I have a log file which has a basic format of this... 2010-10-10 22:25:42 Init block 'UA Deployment Date': Dynamic refresh of repository scope variables has failed. The ODBC function has returned an error. The database... (4 Replies)
Discussion started by: k1ko
4 Replies

6. Shell Programming and Scripting

parsing multi-date text file

Hi all: Trying to parse a log file of rsync activity to get the amount of date being transferred. The log file contains multiple dates and what I am trying to do is get the file sizes for the current date. What I have been trying to do is pipe it through awk but I am having trouble retrieving... (1 Reply)
Discussion started by: raggmopp
1 Replies

7. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

8. Shell Programming and Scripting

Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names

I'm trying to write a script that will look in an /exports folder for the oldest export file and move it to a /staging folder. "Oldest" in this case is actually determined by date information embedded in the file names themselves. Also, the script should only move a file from /exports to... (6 Replies)
Discussion started by: nikosey
6 Replies

9. Shell Programming and Scripting

Date parsing into string, help!

I have a file that was created yesterday that I want to access... daily.log2008-02-16 I am using... curr_time=`date +"%Y %m %d"` yesterday=`./datecalc.ksh -a $curr_time - 1` the value for yesterday is now "2008 2 16" in ksh, how do I transform the string "2008 2 16" into "2008-02-16" (5 Replies)
Discussion started by: martyb555
5 Replies

10. Shell Programming and Scripting

parsing a system log file via the 'date' command

Hello, I'm trying to update some scripts here that parse our system logs daily. They report information just fine... but they just report too much info. Specifically, if there's been some failed login attempts on several different days (say Monday and Tuesday), when I get the report from... (5 Replies)
Discussion started by: cjones
5 Replies
Login or Register to Ask a Question