Add CRs (newlines)

 
Thread Tools Search this Thread
Operating Systems OS X (Apple) Add CRs (newlines)
# 8  
Old 03-27-2009
Shell method:
awk '{gsub("XXX","\r");print}' yourfile > newfile

I searched UNIX.COM for "awk global replace" and found help in the sixth returned link.

You should try that with "vi global replace" if you are determined to do it in vi.
Use the whacky search button in the upper right corner of the page.
Smilie
# 9  
Old 03-27-2009
Quote:
Originally Posted by Gale Gorman
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.
Did you try replacing the "^M" with "\r"?
# 10  
Old 03-27-2009
Removal is not a problem. The only file I have has one line with >400,000 characters. Where ^M was at one time now has XXX but this is still all on one line.

I need to insert a carriage return at every instance of ^M.

tr, awk, or simply substitution with vi will work but I'm not using the proper syntax to get a carriage return or newline.

***********
Just tried a few more and one worked!!

within vi....
:%s/XXX/\r/g

changed them all.

I would not have thought of trying \r had I not seen that in your awk statement.

Thanks!
# 11  
Old 03-27-2009
Or if OS X has dos2unix(1) then:

Code:
$ dos2unix inputfile.dos.txt > outputfile.unix.txt

would do the trick.

dos2unix for OS X seems to be available from here: Dos2unix version 3.1 - How to Download and Install on Mac OS X
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