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 and shell scripting languages 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 04: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
Date and time log file captoro Shell Programming and Scripting 8 09-03-2007 10:23 PM
how do I put a date and time in a file name jhamm UNIX for Dummies Questions & Answers 2 01-16-2007 09:31 AM
File date and time stamp Xenon UNIX for Dummies Questions & Answers 1 10-09-2001 04:58 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-04-2007
skumar11 skumar11 is offline
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 06:09 PM..
  #2 (permalink)  
Old 09-04-2007
digen digen is offline
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
  #3 (permalink)  
Old 09-04-2007
skumar11 skumar11 is offline
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.
  #4 (permalink)  
Old 09-04-2007
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
Using gnu sed...
Code:
sed -r 's! ..?/..?/.. ..:..:..!!g' file1 > file2

  #5 (permalink)  
Old 09-05-2007
skumar11 skumar11 is offline
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.
  #6 (permalink)  
Old 09-05-2007
skumar11 skumar11 is offline
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.
  #7 (permalink)  
Old 09-05-2007
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,365
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.)
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 06:25 PM.


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