Help needed - Replacing all date & time occurrences in a file with a string using Sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help needed - Replacing all date & time occurrences in a file with a string using Sed
# 1  
Old 11-10-2005
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.
# 2  
Old 11-10-2005
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

# 3  
Old 11-11-2005
Bug Thank you very much..it's really working very well..

Hi Vino,
Thank you very much for your help...
# 4  
Old 11-16-2005
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  
Old 11-17-2005
Go to the forums' faq. You will some sed tutorials there.

Unix Tutorials/Programming Tutorials/Shell Scripting Tutorials

vino
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to print & and \n while replacing with sed/awk?

string="din&esh\nisgood" File.txt: the name is sed "s#\#${string}#g" File.txt Output am getting: the name is dinesh is good Expected output: the name is din&esh\nisgood The input string is dynamic it will be keep on changing am able to handle & by placing \& in the string.. (5 Replies)
Discussion started by: dineshaila
5 Replies

2. Shell Programming and Scripting

Replacing FQDN by hostnames in a CSV file with sed & awk

Hello, Beginning with shell scipting, I'm trying to find in a csv file, the lines where the field related to hostname is displayed as an FQDN intead the hostname. (some lines are correct) and the to correct that inside the file: Novell,11.0,UNIX Server,bscpsiws02,TxffnX1tX1HiDoyBerrzWA==... (2 Replies)
Discussion started by: Wonto
2 Replies

3. Shell Programming and Scripting

Filter date and time form a file using sed command

I want to filter out the date and time from this line in a file. How to do this using sed command. on Tue Apr 19 00:48:29 2011 (12 Replies)
Discussion started by: vineet.dhingra
12 Replies

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

5. Shell Programming and Scripting

Convert Epoch Time to Standard Date and Time & Vice Versa

Hi guys, I know that this topic has been discuss numerous times, and I have search the net and this forum for it. However, non able to address the problem I faced so far. I am on Solaris Platform and unable to install additional packages like the GNU date and gawk to make use of their... (5 Replies)
Discussion started by: DrivesMeCrazy
5 Replies

6. Shell Programming and Scripting

grep to show date/time of file the string was found in.

I've seen several examples of grep showing the filename the string was found in, but what I really need is grep to show the file details in long format (like ls -l would). scenario is: grep mobile_number todays_files This will show me the string I'm after & which files they turn up in, but... (2 Replies)
Discussion started by: woodstock
2 Replies

7. Shell Programming and Scripting

Replacing Last occurance of &amp; from a string

Hi All, Could anyone help me out in the below requirement: I have a text(XML) file like this: - <Dim2> <Properties Name="" State="2" ShowHir="-1" ApplyFilter="-1" ExpandToLevel="1" BreakHierType="1" MaxDepth="1" SlicerSelectOptions="1" ShowLeaf="0" HasGroup="0" /> <Expanded... (1 Reply)
Discussion started by: vivekshady
1 Replies

8. Shell Programming and Scripting

Problem to add the string(without sed & awk) into the middle of file

Hi, I have tried many times to add the string into the first line of the file or the middle of the file but could not find the solution. I first tried by $echo "paki" >> file This code only append paki string at the end of file "file" but how can i add this "paki" into the first line or... (5 Replies)
Discussion started by: ali hussain
5 Replies

9. UNIX for Dummies Questions & Answers

Inserting Date&Time Stamp In Existing Log File

I am trying to insert a line with a date stamp in a file that is used to monitor activity in one of our directories. By doing this, I want to grep that file each day and go to the last entry for each time a error occurred and pull all errors generated if any exist. If error exists I want that error... (3 Replies)
Discussion started by: shephardfamily
3 Replies

10. UNIX for Dummies Questions & Answers

file creation date & time

Hi All, I have some files which are creates every day using a script. I want to create a log files which does write "filename,creation day and time" how can I do this ?? Alice (3 Replies)
Discussion started by: alisevA3
3 Replies
Login or Register to Ask a Question