Add CRs (newlines)

 
Thread Tools Search this Thread
Operating Systems OS X (Apple) Add CRs (newlines)
# 1  
Old 03-26-2009
Add CRs (newlines)

I have a long file originally created with vi but at some point saved with MS Word. At another time I substituted all occurrences of ^M with XXX. Now I'd like to get this back to vi but with the XXX converted to newline.

I'm using whatever version of vim Apple employs.

Thanks,

Gale
# 2  
Old 03-27-2009
You can try something like this:

Code:
awk '{sub("XXX","");print}' file > newfile

Regards
# 3  
Old 03-27-2009
Thanks, I've been trying to do this in vi with:

:%s/XXX/^M/g

and all I get are the ^Ms when I wanted a carriage return.

BTW I know to use ctrl-v before the M.
# 4  
Old 03-27-2009
In this awk line won't "" just remove each occurrence of XXX?
# 5  
Old 03-27-2009
It removes one occurrence in a line, I suppose you have one occurrence of XXX at the end of the line?
I'm not shure I understand what you're trying to achieve. Do you want to convert the file to dos/windows format?

Regards
# 6  
Old 03-27-2009
I thought my original message was clear.

This is one long file in a single line. Wherever XXX appears I need a carriage return or newline so the file can be read and edited with vi.

So I'm not just trying to get rid of XXX, I'm trying to REPLACE them with a carriage return.

I originally screwed up this file after it had been saved in MS Word and of course there was a ^M everywhere.

I used the substitute command in vi to get rid of those ^Ms but still didn't achieve the result I wanted. Then I substituted XXX for ^M with:

:%s/^M/XXX/g
# 7  
Old 03-27-2009
If you still have the original file with a ^M after each line you can remove them with:

Code:
tr -d '\r' < your_file > new_file

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX file with Newlines

Hi Friends, I have a data file with new lines. How to remove the newlines and should be showed in one line. I tried using the command tr -d '\n' filename sed 's/\n//g' file name Ex: 1 abc hyd is actual record but in our scenario showing it as 1 abc hydthis record should be like... (5 Replies)
Discussion started by: victory
5 Replies

2. UNIX for Dummies Questions & Answers

Remove newlines

Hi buddy's my file are like this: s.no,name,band,sal 1,"suneel",,10 2,"bargav sand",,20 30," ebdug gil",,4 but i want s.no,name,band,sal 1,"suneel",,10 2,"bargav sand",,20 30,"ebdug gil",,4 any command or Shell script for this. please help me it's urgent to implement (33 Replies)
Discussion started by: Suneelbabu.etl
33 Replies

3. Red Hat

User shutdown detected - cssd(16694)CRS-1603:CSSD.

User shutdown detected - cssd(16694)CRS-1603:CSSD. Can you help me with this error in redhat linux server (1 Reply)
Discussion started by: karthik9358
1 Replies

4. Shell Programming and Scripting

Need help with eliminating newlines with Perl

Good morning, I need some help with getting rid of newlines with the output from a MYSQL query and putting the information into the right format that I need. Here is the script as it is today: #!/usr/bin/perl my $uda = system("/opt/incontrol/mysql/bin/mysql -u root -ppassword... (2 Replies)
Discussion started by: brianjb
2 Replies

5. Shell Programming and Scripting

removing newlines after a certain word.

Hello! This is my first post here. I have a file with text like: A</title> B C</title> D I need to format it to: AB CD I am trying to use sed: sed 's/<//title>\n/ /g' file > newfile to delete </title> and the newline character, but the file is unchanged because there are... (3 Replies)
Discussion started by: DaytonCPS
3 Replies

6. Shell Programming and Scripting

Extract pattern before two newlines

Hi All, My file looks like this: 1 2 3 3 4 5 6 7 8 8 7 6 3 4 5 3 6 7 3 4 5 1 2 4 3 4 6 2 4 6 As you can see there are two newlines after the next pattern of numbers begin. (4 Replies)
Discussion started by: shoaibjameel123
4 Replies

7. Shell Programming and Scripting

Ignoring newlines in my search

I have a file that has lines that are deliminated with '^A', but some of the lines go for a few lines and I need those lines to be appended into one line. All of the lines start with 'low debug' and end with ' " 0 '. How can I read each line from start to finish without some of the data... (7 Replies)
Discussion started by: ndedhia1
7 Replies

8. Shell Programming and Scripting

Remove improperly placed newlines

Hello, there. I have a file that's a horrible, horrible mess. (Basically, it's an export from a firewall config.) The people who generated the file didn't think that putting a newline in the middle of a hostname would ever be a problem. It is. Here's an example of the stuff in the file: ... (2 Replies)
Discussion started by: mikesimone
2 Replies

9. Shell Programming and Scripting

Transpose with two newlines as delimiter

Hi Guys, I have data in a file as follows: a 1 2 3 b 4 5 6 a 6 7 8 a 4 7 9 b 6 8 5 c 0 8 7 So the number of rows which have data is variable (2 for the first group, one for the second group and three for the third group), but the delimiters between the... (10 Replies)
Discussion started by: npatwardhan
10 Replies
Login or Register to Ask a Question