The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl: Extracting date from file name and comparing with current date MKNENI Shell Programming and Scripting 4 03-26-2008 01: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 08:23 AM
Date and time log file captoro Shell Programming and Scripting 8 09-03-2007 06:23 PM
how do I put a date and time in a file name jhamm UNIX for Dummies Questions & Answers 2 01-16-2007 06:31 AM
File date and time stamp Xenon UNIX for Dummies Questions & Answers 1 10-09-2001 12:58 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 09-04-2007
Registered User
 

Join Date: Sep 2007
Posts: 13
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 02:09 PM.
Reply With Quote
Forum Sponsor
  #2  
Old 09-04-2007
Registered User
 

Join Date: Feb 2007
Posts: 4
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
Reply With Quote
  #3  
Old 09-04-2007
Registered User
 

Join Date: Sep 2007
Posts: 13
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.
Reply With Quote
  #4  
Old 09-04-2007
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,248
Using gnu sed...
Code:
sed -r 's! ..?/..?/.. ..:..:..!!g' file1 > file2
Reply With Quote
  #5  
Old 09-05-2007
Registered User
 

Join Date: Sep 2007
Posts: 13
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.
Reply With Quote
  #6  
Old 09-05-2007
Registered User
 

Join Date: Sep 2007
Posts: 13
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.
Reply With Quote
  #7  
Old 09-05-2007
cfajohnson's Avatar
Registered User
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 791
Quote:
Originally Posted by skumar11 View Post
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.)
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 03:44 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0