Extracting date & time from file name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting date & time from file name
# 1  
Old 10-18-2010
Extracting date & time from file name

Hi,

I am having a file name as exp_bkp_tables_18_Oct_2010_10_50_28.dmp which is used for import the records.

Now, I want to print the output using the selected file name as below :

Table records will get restored as on date 18-Oct-2010 and time 10:50:28

How it can be done ?

With Regards
# 2  
Old 10-18-2010
Something like this ?
Code:
echo "exp_bkp_tables_18_Oct_2010_10_50_28.dmp" | awk -F"_" '{print "Table records will get restored as on date " $4"-"$5"-"$6 " and time " $7":"$8":" substr($9,1,(length($9)-4))}'

This User Gave Thanks to pravin27 For This Post:
# 3  
Old 10-18-2010
Code:
echo "${filename%%.*}" | cut -d_ -f4- | ( IFS=_ ; read d m Y H M S )

echo "Table records will get restored as on date $d-$m-$Y and time $H:$M:$S"

Same but a bit optimized :

Code:
echo "${filename%%.*}" | ( IFS=_ ; read d d d d m Y H M S )
echo "Table records will get restored as on date $d-$m-$Y and time $H:$M:$S"


Last edited by ctsgnb; 10-18-2010 at 10:20 AM..
# 4  
Old 10-18-2010
The below line may help...

Code:
echo "exp_bkp_tables_18_Oct_2010_10_50_28.dmp" | awk -F"_" '{ print  $4 "-"$5"-"$6" and time "$7":"$8":"$9}'

# 5  
Old 10-18-2010
Hi,

Your help is highly appreciated. Thanks for the same.

One more query...regarding sort the files in descending order having name as below:

exp_bkp_tables_18_Oct_2010_10_50_28.dmp
exp_bkp_tables_18_Oct_2010_10_57_00.dmp
exp_bkp_tables_17_Oct_2010_10_58_00.dmp
exp_bkp_tables_17_Oct_2010_10_59_00.dmp

want to display the list of ten latest export copy in descending order

How it can be done ?

With Regards
# 6  
Old 10-18-2010
latest on top
Code:
ls -t *.dmp | head

or
latest on bottom
Code:
ls -rt *.dmp | tail

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting log files based on date and time.

Hi All, i have some log files generated in a folder daily with the format abc.def.20130306.100001 ghi.jkl.20130306.100203 abc.def.20130305.100001 ghi.jkl.20130305.100203 the format is the date followed by time . all i want is to get the files that are generated for todays... (3 Replies)
Discussion started by: mahesh300182
3 Replies

2. Programming

DATE & TIme

Can we select the datetime from oracle database in “hhmmssnnnccyymmdd” format ? please help to solve this..... (2 Replies)
Discussion started by: Sanal
2 Replies

3. Shell Programming and Scripting

About date & time difference

Hello All, I was having a look on threads on the Forum about time calculation but didn't find exactly this issue. For instance, if we have these 2 dates, begin & end : 20100430235830 20100501000200 Is there anyway, awk, ksh, perl to calculate the difference in sec and get for... (6 Replies)
Discussion started by: rany1
6 Replies

4. Shell Programming and Scripting

Convert Epoch Time to Standard Date and Time & Vice Versa

Hi guys, I know that this topic has been discuss numerous times, and I have search the net and this forum for it. However, non able to address the problem I faced so far. I am on Solaris Platform and unable to install additional packages like the GNU date and gawk to make use of their... (5 Replies)
Discussion started by: DrivesMeCrazy
5 Replies

5. Shell Programming and Scripting

Extracting date-time from file.

I have the following file and need to extract date and time part for each record. Pl. could anyone provide an shell script which could be used to do it. Here is the file: /rgrdev/pdsud2/unx/agc/src/agcmst: /rgrsrc/pdspms/unx/agc/src/s.agcmst.for agcmst.for 420.20 8/4/07 18:30:53 ... (7 Replies)
Discussion started by: skumar11
7 Replies

6. UNIX for Dummies Questions & Answers

Inserting Date&Time Stamp In Existing Log File

I am trying to insert a line with a date stamp in a file that is used to monitor activity in one of our directories. By doing this, I want to grep that file each day and go to the last entry for each time a error occurred and pull all errors generated if any exist. If error exists I want that error... (3 Replies)
Discussion started by: shephardfamily
3 Replies

7. Shell Programming and Scripting

Help needed - Replacing all date & time occurrences in a file with a string using Sed

Hi, I am new to using Sed. I have a file containg lines like the following: INFORM----Test.pc:168:10/11/05 12:34:26 > some text goes here.. TRACE-----Test.pc:197:10/11/05 12:34:26 > some text goes here.. My requirement is to replace 10/11/05 12:34:26 with a string <RUNDATE> (including <... (4 Replies)
Discussion started by: Hema_M
4 Replies

8. UNIX for Dummies Questions & Answers

Backup Date & Time

:confused: I'm not really sure about the default backup date & time in our Unix system and I would like to change it to a convienient time...how do I do that? Please help? (1 Reply)
Discussion started by: EbeyeJJ
1 Replies

9. UNIX for Dummies Questions & Answers

file creation date & time

Hi All, I have some files which are creates every day using a script. I want to create a log files which does write "filename,creation day and time" how can I do this ?? Alice (3 Replies)
Discussion started by: alisevA3
3 Replies

10. UNIX for Dummies Questions & Answers

Time & Date Command

Hey all, When you run the 'ls -la' command it'll show you the time and dates of all files/directories. Now what I am trying to do is create a script that will tell me what files haven't been used in over the past 1 month and what the time and date is that the files that haven't been accessed in... (2 Replies)
Discussion started by: merlin
2 Replies
Login or Register to Ask a Question