The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
extract last modified time of file in form of YYYYMMDD itsme_maverick Shell Programming and Scripting 3 05-28-2008 12:01 PM
Processing a log file based on date/time input and the date/time on the log file primp Shell Programming and Scripting 4 03-16-2008 11:23 AM
Extract Date from file magi Shell Programming and Scripting 2 09-30-2007 12:07 AM
Date and time log file captoro Shell Programming and Scripting 8 09-03-2007 09:23 PM
extract date portion from file misenkiser Shell Programming and Scripting 5 10-06-2006 05:37 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-06-2006
prash_b prash_b is offline
Registered User
  
 

Join Date: May 2006
Posts: 5
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 (permalink)  
Old 10-06-2006
mona's Avatar
mona mona is offline
Registered User
  
 

Join Date: Nov 2005
Location: Singapore
Posts: 96
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 (permalink)  
Old 10-06-2006
prash_b prash_b is offline
Registered User
  
 

Join Date: May 2006
Posts: 5
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 (permalink)  
Old 10-06-2006
justsam
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
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
  #5 (permalink)  
Old 10-06-2006
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,509
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 (permalink)  
Old 06-18-2008
anshuman anshuman is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 1
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0