How to extract date with time from file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to extract date with time from file
# 1  
Old 10-06-2006
How to extract date with time from file

Hi,

I have a file where there is a date and time field, the format for it is yyyy-mm-dd hours:mins:sec

the position of date field may vary anywhere in the line and it might be different and it is specified along with the variable AppTimeStamp

how do i extract date and time both from the line

for eg .

xxxxxxxxxxxxxxx<AppTimeStamp>09-10-2006 12:10:01<\AppTimeStamp>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx<AppTimeStamp>10-12-02 10:05:00<\AppTimeStamoxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Please can anybody help me with this
# 2  
Old 10-06-2006
You might want to check this link.

Please use the search utility in this forum. You will find quite a number of threads useful regarding date manipulation
# 3  
Old 10-06-2006
Hi,

Thanks for the link,

I tried the same, but it did not work,

here is the sample file i am using
<xxxx><xxxxx><xxxxx><AppEventTimeStamp>2006-05-02 09:25:00</AppEventTimeStamp><xxxx><xxxx>345</xxx><AppEventTimeStamp>2006-10-18 10:25:00</AppEventTimeStamp><xxxxxx><\xxxxxxxx>

The format i am searching for is "year-mon-day hour-min-sec"

could you please help me out with this
# 4  
Old 10-06-2006
Just change the search pattern present in the above link mentioned by misenkiser
sed 's/^.*\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\} [0-2][0-4]:[0-5][0-9]:[0-5][0-9]\).*$/\1/' file name
justsam
# 5  
Old 10-06-2006
Python Alternative:

Code:
#!/usr/bin/python
import re #regular exp module
data = open("input.txt").read()
print re.findall("<AppEventTimeStamp>(.*?)</AppEventTimeStamp>",data)

Output:
Code:
['2006-05-02 09:25:00', '2006-10-18 10:25:00']

# 6  
Old 06-18-2008
help required

i need to extract teh date only from
INTERFACE_HEAD|2005/12/27|22:30:59|CMT|
and not the time..ie in teh format yyyy/mm/dd

can any body help
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract date and time part from filename

Hi, I am facing one scenario in which I need to extract exact position of date and time from the name of the files. For example, Below is the record in which I need to extract position of YYYYMMDD,HHMISS and YYMMDD. Date and time variables can come more than once. I need to use these position... (13 Replies)
Discussion started by: Prathmesh
13 Replies

2. UNIX for Beginners Questions & Answers

How to extract date and time from filename?

Hi, I'm totally new in sell script and working with a shell code. I want to extract the date and time from the filenames. The filenames are different but all of them begins with WI_ SCOPE_: WI_SCOPE_DATA_CHANGE_2017-09-12_15-30-40.txt WI_SCOPE_BACK_COMPLETE_QUEUE_2017-09-12_15-31-40.txt... (5 Replies)
Discussion started by: Home
5 Replies

3. UNIX for Dummies Questions & Answers

How to extract date from a file?

Hello Gurus, I have one file from which I want to extract only dates. The below is the file format : ========================= Process ID 16842770 Log Read Checkpoint Oracle Integrated Redo Logs 2014-07-04 17:06:11 <=== SCN 1779.852353022 (7641599172606) Process ID ... (6 Replies)
Discussion started by: pokhraj_d
6 Replies

4. Shell Programming and Scripting

Extract date / time

How do i display in the below format without the brackets using shell script. Tue Oct 1 13:32:40 2013 Please use CODE tags not only for all code segments, input samples, and output samples. (7 Replies)
Discussion started by: ghosh_tanmoy
7 Replies

5. Shell Programming and Scripting

How to extract latest file by looking at date time stamp from a directory?

hi, i have a Archive directory in which files are archived or stored with date and time stamp to prevent over writing. example: there are 5 files s1.txt s2.txt s3.txt s4.txt s5.txt while moving these files to archive directory, date and time stamp is added. of format `date... (9 Replies)
Discussion started by: Little
9 Replies

6. Shell Programming and Scripting

To extract date and time separately from the file name

Hi., My current script extracts only if the date and time are in 3rd and 4th pos. #!/bin/bash echo "Enter the file name to extract the timestamp" read fname IFILE=$fname F=$IFILE IFS="_." f=($F) echo "Date ${f} Time ${f}" How to generalize the script to extract the... (3 Replies)
Discussion started by: IND123
3 Replies

7. Shell Programming and Scripting

Extract info from log file and compute using time date stamp

Looking for a shell script or a simple perl script . I am new to scripting and not very good at it . I have 2 directories . One of them holds a text file with list of files in it and the second one is a daily log which shows the file completion time. I need to co-relate both and make a report. ... (0 Replies)
Discussion started by: breez_drew
0 Replies

8. Shell Programming and Scripting

To extract data of a perticular interval (date-time wise)

I want a shell script which extract data from a log file which contains date and time-wise data and i need the data for a perticular interval of time...what can i do??? (3 Replies)
Discussion started by: abhishek27
3 Replies

9. Shell Programming and Scripting

Processing a log file based on date/time input and the date/time on the log file

Hi, I'm trying to accomplish the following and would like some suggestions or possible bash script examples that may work I have a directory that has a list of log files that's periodically dumped from a script that is crontab that are rotated 4 generations. There will be a time stamp that is... (4 Replies)
Discussion started by: primp
4 Replies

10. Shell Programming and Scripting

Extract Date from file

I am new to unix scripting. we are using bash. My task is I have dir which contains 30 files. The first column in each file is Date field. For all the files I need to extract the date part Ex(2007-09-05) from the file and add that at the end of that file. for example: The file names are... (2 Replies)
Discussion started by: magi
2 Replies
Login or Register to Ask a Question