How to replace 0a with 0d0a in the text file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to replace 0a with 0d0a in the text file?
# 1  
Old 05-12-2009
Question How to replace 0a with 0d0a in the text file?

Hello,
I must replace all occurences of 0a character in a text file with 2 characters 0d0a. I've tried sed, but it cannot insert control characters ie. \n \r - it simply writes \n \r into output file. What is the good solution for my problem? I use ksh and AIX 5.3 operating system.

Tia
Yac
# 2  
Old 05-12-2009
If available: unix2dos
Otherwise:
Code:
perl -i.bak -pe 's/\n/\r\n/' file

# 3  
Old 05-12-2009
try this out
cat filename | sed 's/Oa/\n/'
# 4  
Old 05-12-2009
Unfortunately these 2 solutions above didn't work for me... I must probably get the unix2dos tool...
# 5  
Old 05-12-2009
Another one: if you've got vim available (vim, not vi), in command mode enter
Code:
:set fileformat=dos

and save, and it should be converted.
# 6  
Old 05-12-2009
Quote:
Originally Posted by Yac
Unfortunately these 2 solutions above didn't work for me... I must probably get the unix2dos tool...
Code:
awk '{print $0 "\r"}' filename

or
Code:
awk '{printf("%s\r\n", $0)}'  filename

# 7  
Old 05-12-2009
Or

Code:
awk 'BEGIN {RS="\n";ORS="\r\n"} {print $0}' filename

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace text in a file

I wrote a program using Perl to find and replace a text within a file. The text that needs to be replaced in the file is 'sql7.0.1' with 'sqls715'. When I execute my program I get an error message: Here is my code: #!/usr/bin/perl use strict; use warnings; my $filename =... (6 Replies)
Discussion started by: dellanicholson
6 Replies

2. Shell Programming and Scripting

Bash script to replace text file from a lookup file

Hi. I need assistance with the replacing of text into a specific file via a bash script. My bash script, once run, currently provides a menu of computer names to choose.The script copies onto my system various files, depending what computer was selected in the menu.This is working OK. Now, I... (1 Reply)
Discussion started by: jonesn2000
1 Replies

3. Windows & DOS: Issues & Discussions

2 Questions: replace text in txt file, add text to end of txt file

so... Lets assume I have a text file. The text file contains multiple "#" symbols. I want to replace all thos "#"s with a STRING using DOS/Batch I want to add a certain TEXT to the end of each line. How can I do this WITHOUT aid of sed, grep or anything linux related ? (1 Reply)
Discussion started by: pasc
1 Replies

4. Shell Programming and Scripting

Search and replace from file in awk using a 16 bit text file

Hello, Some time ago a helpful awk file was provided on the forum which I give below: NR==FNR{A=$0;next}{for(j in A){split(A,P,"=");for(i=1;i<=NF;i++){if($i==P){$i=P}}}}1 While it works beautifully on English and Latin characters i.e. within the ASCII range of 127, the moment a character beyond... (6 Replies)
Discussion started by: gimley
6 Replies

5. Shell Programming and Scripting

Replace text in column1 of a file matching columns of another file

Hi all, I have 2 files: species-names.txt Abaca-bunchy-top-virus ((((Abaca-bunchy-top-virus((Babuvirus((Unassigned((Nanoviridae((Unassigned)))) Abutilon-mosaic-virus ((((Abutilon-mosaic-virus((Begomovirus((Unassigned((Geminiviridae((Unassigned))))... (2 Replies)
Discussion started by: thienxho
2 Replies

6. Shell Programming and Scripting

How to replace a text in a file conditionally?

I have got about 100 ascii files and I want replace some variable with a new one on an HP-UX system. But I want to put a line of comments before the change. I want to make file1 to file2. I am explaining below. file1: line1 line2 export QNAME=ABC line4 line5 file2: line1 line2 #... (3 Replies)
Discussion started by: asutoshch
3 Replies

7. Shell Programming and Scripting

replace text in file using variable

Hi, I'm making a script that automaticaly set file size and path in xml file. I tried with : sed -i 's/BOOTPATH/TEST/g' file.xml it works fine but if I use a viriable : sed -i 's/BOOTPATH/$bootpathf/g' file.xml with this one, no change are made. I don't understand why. If a make a ... (13 Replies)
Discussion started by: Toug
13 Replies

8. Shell Programming and Scripting

How to replace text in a file with text entered

I am trying to write a shell script that will allow the typing of a value, then using that value to replace data in a text file. I suspect I need sed. The format of the file is: Variable1:Value1 Variable2:Value2 The interaction would be something like: Shell Prompt: "Please enter the... (9 Replies)
Discussion started by: cleanden
9 Replies

9. UNIX for Dummies Questions & Answers

how can search a String in one text file and replace the whole line in another file

i am very new to UNIX plz help me in this scenario i have two text files as below file1.txt name=Rajakumar. Discipline=Electronics and communication. Designation=software Engineer. file2.txt name=Kannan. Discipline=Mechanical. Designation=CADD Design Engineer. ... (6 Replies)
Discussion started by: kkraja
6 Replies

10. UNIX for Dummies Questions & Answers

search and replace a specific text in text file?

I have a text file with following content (3 lines) filename : output.txt first line:12/12/2008 second line:12/12/2008 third line:Y I would like to know how we can replace 'Y' with 'N' in the 3rd line keeping 1st and 2nd lines same as what it was before. I tried using cat output.txt... (4 Replies)
Discussion started by: santosham
4 Replies
Login or Register to Ask a Question