replacing text in an ascii doc


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting replacing text in an ascii doc
# 1  
Old 09-28-2005
replacing text in an ascii doc

What would be the best way to replace all instances of...

09/26/2005
with
20050926

There are no spaces between the the date and the preceeding and following data. example lines looks like...

snp01|NAME/OF/A/GROUP|09/26/2005081343|502

the 081343 is the time without colons.

Thank you.
# 2  
Old 09-28-2005
Code:
ruby -pe'sub(%r!(\d\d)/(\d\d)/(\d{4})!,"\\3\\1\\2")'

# 3  
Old 09-28-2005
????

Could you explain that more...

I'm using the korn shell. How would I use ruby inside a korn script.
# 4  
Old 09-28-2005
the sed command

I tried using the sed command, but it's doesn't do anything...

sed -e 's/$date/$newDate/g' $ofile > test.txt
# 5  
Old 09-28-2005
Quote:
I tried using the sed command, but it's doesn't do anything...

sed -e 's/$date/$newDate/g' $ofile > test.txt
Code:
sed -e "s#$date#$newDate#g" $ofile > test.txt

# 6  
Old 09-28-2005
...

that sed command is not working for me...

I was going to try using this to do it, but it won't pass the variable to it...

/bin/echo '%s/^/"$newDate "/g\nwq!' | ex - $ofile
# 7  
Old 09-29-2005
MySQL

Please check one again, I tried sed command suggested above works perfectly.


Here is the test:

Code:
 >more g
09/26/2005
 >echo $old_date
09/26/2005
 >echo $new_date
20050926
 >sed -e "s:$old_date:$new_date:g" g
20050926

The ex command is not working because the subsitute pattern will fail becuase of backslashes in variable itself.

rishi
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Convert ASCII Text, with CRLF

1. The problem statement, all variables and given/known data: write a script asciiFix.sh that takes an arbitrary number of file paths from the command line and carries out the same analysis on each one. If a file is not Windows ASCII, your script should do nothing to it. For each file that is... (7 Replies)
Discussion started by: kwatt019
7 Replies

2. Shell Programming and Scripting

Import ASCII 28 delimited text file

I have an ASCII 28 delimited text file(non-printable delimiter) with 4 columns along with the header.I need to open this text file in Excel or any other tool to view each column content. Please help.. Thanks (6 Replies)
Discussion started by: aneeta13
6 Replies

3. Shell Programming and Scripting

Binary to ASCII(TEXT converion)

Hi all, I have been trying to convert a binary file to TEXT/ASCII file in linux/solaries.and commands like string are no good.Also i am not sure how the how output of the file looks like... I am attaching the binary file as zip since i couldnt load it in its original form in the post incase... (1 Reply)
Discussion started by: pistachio
1 Replies

4. Shell Programming and Scripting

ASCII Text formatting

Hi All, I have a requirement to create a formatted text. That is., I have a plain text composed to send it through an Email using mailx. I need to change the formatting of the text like BOLD, ITALIC, UNDERINED, COLOURED, INDENT etc., First of all, is it possible in UNIX? If yes, please let... (3 Replies)
Discussion started by: mohan_kumarcs
3 Replies

5. Programming

Reading a binary file in text or ASCII format

Hi All, Please suggest me how to read a binary file in text or ASCII format. thanks Nagendra (3 Replies)
Discussion started by: Nagendra
3 Replies

6. Shell Programming and Scripting

mbox ascii mail text file ?

Hi, I am using "fetchmail" and "procmail" combination to trigger a job based on an input mail.Using fetchmail, incoming mail is downloaded from the mailserver to the local host.Once the mail is flushed,procmail starts execution and thereby triggers the application script. In-between... (3 Replies)
Discussion started by: DILEEP410
3 Replies

7. Windows & DOS: Issues & Discussions

Unix text doc with a .gif image

I would like to insert a .gif image into a text file that is generated by a Unix-based database application. Can anyone please tell me how I can achieve this? (7 Replies)
Discussion started by: sunita_rao
7 Replies

8. UNIX for Dummies Questions & Answers

Creating flat text file (ASCII)

Hi everybody. I need help and I hope someone is willing to help me out here. My wholesale company is currently moving to new software. The old software is running on a UNIX platform. We need to migrate data from the UNIX system, but our former software provider refuses to assist the data... (5 Replies)
Discussion started by: Wdonero
5 Replies

9. UNIX for Advanced & Expert Users

converting PDF to text, rtf doc format

Hi all Is there any program which can convert PDF to word processor file ? If the PDF has smart quotes, bullet icons, copyright and trademark symbols, etc. what happens to them intext format? So ideally would like to conver into rtf or doc. Thanks SS (1 Reply)
Discussion started by: saurya_s
1 Replies

10. UNIX for Dummies Questions & Answers

convert hex to ascii text

Is there a command to convert hex characters into their respective ascii values? (5 Replies)
Discussion started by: dangral
5 Replies
Login or Register to Ask a Question