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
replacing string in an XML file subin_bala Shell Programming and Scripting 2 06-03-2008 04:14 AM
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
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
replacing a string in a file with command line parameter chiru_h Shell Programming and Scripting 5 08-03-2006 06:34 AM
Replacing a character string in a file rjsha1 Shell Programming and Scripting 12 12-14-2005 10:56 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-10-2005
Registered User
 

Join Date: Nov 2005
Posts: 5
Help needed - Replacing all date & time occurrences in a file with a string using Sed

Hi,
I am new to using Sed. I have a file containg lines like the following:

INFORM----Test.pc:168:10/11/05 12:34:26 > some text goes here..

TRACE-----Test.pc:197:10/11/05 12:34:26 > some text goes here..

My requirement is to replace 10/11/05 12:34:26 with a string <RUNDATE> (including < & >).

Can anyone help me how to acheive this using Sed? I need this urgently..

I have tried this:
cat test.result | sed -e 's/[A-Z,a-z,-,_]\.pc[0-9,-,_]/\[A-Z,a-z,-,_]\.pc\<RUNDATE\>/' > test.result.tmp

But, it's not working.
Reply With Quote
Forum Sponsor
  #2  
Old 11-10-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
Look at this

Code:
sh-2.05b$ echo "INFORM----Test.pc:168:10/11/05 12:34:26 > some text goes here.. " | 
sed -e 's#\(.*\)[0-9][0-9]/[0-9][0-9]/[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9]\(.*\)#\1<RUNDATE>\2#g'

INFORM----Test.pc:168:<RUNDATE> > some text goes here..
Overall it will be as

Code:
sed -e 's#\(.*\)[0-9][0-9]/[0-9][0-9]/[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9]\(.*\)#\1<RUNDATE>\2#g' test.result > test.result.tmp
Reply With Quote
  #3  
Old 11-10-2005
Registered User
 

Join Date: Nov 2005
Posts: 5
Smile Thank you very much..it's really working very well..

Hi Vino,
Thank you very much for your help...
Reply With Quote
  #4  
Old 11-16-2005
Registered User
 

Join Date: Nov 2005
Posts: 5
Need one more help- using sed

Hi Vino,
Once again thank you very much for your help. And as I am new to Sed, can you please explain the command that you have given to me or Also, can you please point me to some good sites where I can learn Sed?
It is working very well, but want to understand its working. I understood little only.

And here is one more problem I am facing, again I need your help:

Error: The directory /logDir/AR_archive/20051116135822 is not writeable

Error: The directory /test/logDir/AR_archive/20051116135822 is not writeable

I need to re-write as:
Error: The directory <AR_archive> is not writeable

I am trying the following:
sed -e 's#\(.*\)[AR_archive]/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\(.*\) #\1<AR_archive>\2#g'

But, it is giving:
Error: The directory /psg/gnanduri/Banksys/logDir/AR_archiv<AR_archive> is notwriteable.
Reply With Quote
  #5  
Old 11-16-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
Go to the forums' faq. You will some sed tutorials there.

Unix Tutorials/Programming Tutorials/Shell Scripting Tutorials

vino
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 06:12 AM.


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