Extracting date-time from file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting date-time from file.
# 1  
Old 09-04-2007
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:
Code:
/rgrdev/pdsud2/unx/agc/src/agcmst:
     /rgrsrc/pdspms/unx/agc/src/s.agcmst.for
     agcmst.for 420.20 8/4/07 18:30:53
     /rgrsrc/pdsbas/unx/agc/src/s.agtrnd.for
     agtrnd.for 2.8 8/4/07 18:30:18
     /rgrsrc/pdspms/unx/agc/src/s.hyagc.for
     hyagc.for 420.2 8/4/07 18:30:36
     /rgrsrc/pdspms/unx/agc/src/s.permon.for
     permon.for 420.24 8/4/07 18:30:43
     /rgrsrc/pdspms/unx/agc/src/s.rescal.for
     rescal.for 420.4 8/4/07 18:30:44
     /rgrsrc/pdspms/unx/agc/src/s.jouflt.for
     jouflt.for 420.6 8/4/07 18:30:38
     ercalm.for pdsras 08/04/07 18:30:32
     /rgrsrc/pdspms/unx/agc/src/s.rtproc.for
     rtproc.for 420.3 8/4/07 18:30:48
     timef.c    1.6 12/12/05 16:09:42 /rgrsrc/pdsbas/unx/forshl/src/s.timef.c
     rlscrf.c   1.4 12/12/05 16:09:36 /rgrsrc/pdsbas/unx/forshl/src/s.rlscrf.c
     GETUCD.c   1.2 5/7/07 16:16:09 /rgrsrc/pdsbas/unx/epashl/src/s.GETUCD.c
     /rgrsrc/pdspms/unx/epashl/src/s.llmvar.for
     llmvar.for 420.2 5/7/07 16:17:36   @(#) /rgrsrc/pdspms/unx/epashl/src/s.rprcal.for
     rprcal.for 420.1 5/7/07 16:18:01    @(#) /rgrsrc/pdspms/unx/epashl/src/s.unmvar.for
     unmvar.for 420.3 5/7/07 16:18:22
     /rgrsrc/pdspms/unx/epashl/src/s.nsrcal.for
     nsrcal.for 420.3 5/7/07 16:17:43   @(#) /rgrsrc/pdspms/unx/epashl/src/s.rrscal.for
     rrscal.for 420.5 5/7/07 16:18:01    @(#) /rgrsrc/pdspms/unx/epashl/src/s.dbecal.for
     dbecal.for 420.5 5/7/07 16:16:54  @(#) /rgrsrc/pdspms/unx/epashl/src/s.ubecal.for
     ubecal.for 420.4 5/7/07 16:18:22  @(#) /rgrsrc/pdspms/unx/epashl/src/s.drscal.for
     drscal.for 420.4 5/7/07 16:17:01   @(#) /rgrsrc/pdspms/unx/epashl/src/s.urscal.for
     urscal.for 420.4 5/7/07 16:18:23   @(#) /rgrsrc/pdspms/unx/epashl/src/s.loscal.for
     loscal.for 420.1 5/7/07 16:17:36
     appalm.c   1.5 5/7/07 16:16:14 /rgrsrc/pdsbas/unx/epashl/src/s.appalm.c
     topchk.c   1.2 3/11/07 20:45:53 /rgrsrc/pdsbas/unx/scs/src/s.topchk.c
     /rgrsrc/pdspms/unx/ed/src/s.findst.for
     findst.for 420.1 6/27/07 09:45:34
    V1.0
    $RCSfile: crt0.s,v $ $Revision: 1.1.26.2 $ (DEC) $Date: 1997/04/03 22:25:40 $


Pl. help me out to find the solution. Early responce highly appreciated.

Last edited by vgersh99; 09-04-2007 at 06:09 PM..
# 2  
Old 09-04-2007
I saved a few sample entries in the file extract and used awk to extract the relevant entries,

Quote:
root@emily:~/networkredux/scripting# cat extract
timef.c 1.6 12/12/05 16:09:42 /rgrsrc/pdsbas/unx/forshl/src/s.timef.c
rlscrf.c 1.4 12/12/05 16:09:36 /rgrsrc/pdsbas/unx/forshl/src/s.rlscrf.c
GETUCD.c 1.2 5/7/07 16:16:09 /rgrsrc/pdsbas/unx/epashl/src/s.GETUCD.c
Quote:
root@emily:~/networkredux/scripting# awk {'print $1,$3,$4'} extract
timef.c 12/12/05 16:09:42
rlscrf.c 12/12/05 16:09:36
GETUCD.c 5/7/07 16:16:09
# 3  
Old 09-04-2007
digen,

Thanks for the response, but i need to keep the original file as it is by removing the date and time from each record(i donn't care if you remove the latter part after date for each record). I want file like this(Just i have taken few lines from file to explain you):

/rgrdev/pdsud2/unx/agc/src/agcmst:
/rgrsrc/pdspms/unx/agc/src/s.agcmst.for
agcmst.for 420.20
/rgrsrc/pdsbas/unx/agc/src/s.agtrnd.for
agtrnd.for 2.8
timef.c 1.6
rlscrf.c 1.4
unmvar.for 420.3
/rgrsrc/pdspms/unx/epashl/src/s.nsrcal.for
nsrcal.for 420.3

Hope this will clarify what i am looking for.
# 4  
Old 09-04-2007
Using gnu sed...
Code:
sed -r 's! ..?/..?/.. ..:..:..!!g' file1 > file2

# 5  
Old 09-05-2007
This sed command is not working. -r option is not valid so i change to -n. When i run this command, it gives message like "sed:Function 's! ..?/..?/.. ..:..:..exitg can not be parsed." when i try to rerun it, it keeps on adding the command and not doing any thing. Pl. could you recheck it.
# 6  
Old 09-05-2007
Is anyone is having the solution for my problem. Pl. let me know asap. Early response is highly appreciated. I am not very good in Shell prog., so pl. provide the complete code.
# 7  
Old 09-05-2007
Quote:
Originally Posted by skumar11
digen,

Thanks for the response, but i need to keep the original file as it is by removing the date and time from each record(i donn't care if you remove the latter part after date for each record). I want file like this(Just i have taken few lines from file to explain you):

/rgrdev/pdsud2/unx/agc/src/agcmst:
/rgrsrc/pdspms/unx/agc/src/s.agcmst.for
agcmst.for 420.20
/rgrsrc/pdsbas/unx/agc/src/s.agtrnd.for
agtrnd.for 2.8
timef.c 1.6
rlscrf.c 1.4
unmvar.for 420.3
/rgrsrc/pdspms/unx/epashl/src/s.nsrcal.for
nsrcal.for 420.3

Hope this will clarify what i am looking for.

Code:
awk '{print $1,$2,$5}' FILE

(It's hard to tell exactly what you want because the lines you posted are wrapping.)
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. Shell Programming and Scripting

extracting data from file using time stamp

Hi Guys ! is it possible to extract lines from a file which satisfy a time contraint for example program should consider two boundaries one current time and second the user define time and then extract all those line which fall into that specified time lets say 10 (user define time) and 12... (5 Replies)
Discussion started by: ourned
5 Replies

3. Shell Programming and Scripting

Extracting data from a log file with date formats

Hello, I have a log file for the year, which contains lines starting with the data in the format of YYYY-MM-DD. I need to get all the lines that contain the DD being 04, how would I do this? I tried using grep "*-*04" but it didn't work. Any quick one liners I should know about? Thank you. (2 Replies)
Discussion started by: cpickering
2 Replies

4. Homework & Coursework Questions

extracting date from log file

You are given a 1 year logfile with each line starting with a date in the form “YYYY-MM-DD”. How would you extract logs from the 4th day of each month and put them into a new file (1 Reply)
Discussion started by: DOkuwa
1 Replies

5. UNIX for Dummies Questions & Answers

Extracting a Time Span from Syslog Messages File

Hi all, I need your help to explain how I can extract a time span from the syslog messages file on a Solaris 10 system. Here is an example extract of the syslog messages: Dec 4 11:51:38 hajap141-0107.nls.jlrint.com 267938: Dec 4 11:51:36: %DOT11-6-DISASSOC: Interface Dot11Radio0,... (4 Replies)
Discussion started by: wthomas
4 Replies

6. Shell Programming and Scripting

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... (5 Replies)
Discussion started by: milink
5 Replies

7. Shell Programming and Scripting

Extracting lines in file based on time

Hi, anyone has any ideas on how do we extract lines from a file with format similiar to this: (based on current time) Jun 18 00:16:50 .......... ............. ............ Jun 18 00:17:59 .......... ............. ............ Jun 18 01:17:20 .......... ............. ............ Jun 18... (5 Replies)
Discussion started by: faelric
5 Replies

8. Shell Programming and Scripting

Convert Epoch time format to normal date time format in the same file

I have a file named "suspected" with series of line like these : {'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '219.78.120.166', 'client_port': 52044, 'client': '10.64.68.44', 'server_port': 8291, 'time': 1226506312L, 'serverhostname': ''} {'protocol': 17, 'service': 'BitTorrent... (3 Replies)
Discussion started by: rk4k
3 Replies

9. Shell Programming and Scripting

Perl: Extracting date from file name and comparing with current date

I need to extract the date part from the file name (20080221 in this ex) and compare it with the current date and delete it, if it is a past date. $file = exp_ABCD4_T-2584780_upto_20080221.dmp.Z really appreciate any help. thanks mkneni (4 Replies)
Discussion started by: MKNENI
4 Replies

10. 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
Login or Register to Ask a Question