The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Operating Systems > OS X (Apple)
.
google unix.com



OS X (Apple) OS X is a line of Unix-based graphical operating systems developed, marketed, and sold by Apple.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Newlines in shell variables narcvs Shell Programming and Scripting 5 03-26-2009 02:54 AM
replacing strings with newlines : sed hkansal Shell Programming and Scripting 3 11-28-2008 01:24 PM
replacing comma's with newlines using sed newbie_coder Shell Programming and Scripting 5 09-28-2008 11:44 PM
textfile into 2 pieces, seperate by newlines. mcW Shell Programming and Scripting 12 09-24-2008 03:02 PM
Bash scripting question re: newlines retrovertigo Shell Programming and Scripting 4 07-06-2007 12:44 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-26-2009
Gale Gorman Gale Gorman is offline
Registered User
  
 

Join Date: Oct 2007
Location: Houston
Posts: 11
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 (permalink)  
Old 03-27-2009
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,215
You can try something like this:

Code:
awk '{sub("XXX","");print}' file > newfile
Regards
  #3 (permalink)  
Old 03-27-2009
Gale Gorman Gale Gorman is offline
Registered User
  
 

Join Date: Oct 2007
Location: Houston
Posts: 11
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 (permalink)  
Old 03-27-2009
Gale Gorman Gale Gorman is offline
Registered User
  
 

Join Date: Oct 2007
Location: Houston
Posts: 11
In this awk line won't "" just remove each occurrence of XXX?
  #5 (permalink)  
Old 03-27-2009
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,215
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 (permalink)  
Old 03-27-2009
Gale Gorman Gale Gorman is offline
Registered User
  
 

Join Date: Oct 2007
Location: Houston
Posts: 11
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 (permalink)  
Old 03-27-2009
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,215
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
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 12:34 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0