![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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.. 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 |
|
#3
|
|||
|
|||
|
Hi Vino,
Thank you very much for your help... |
|
#4
|
|||
|
|||
|
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. |
|
#5
|
||||
|
||||
|
Go to the forums' faq. You will some sed tutorials there.
Unix Tutorials/Programming Tutorials/Shell Scripting Tutorials vino |
||||
| Google The UNIX and Linux Forums |