Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > macOS > Removing text file EOL?

Removing text file EOL?
Thread Tools
jgift
Dedicated MacNNer
Join Date: Feb 2003
Status: Offline
Reply With Quote
Jul 12, 2005, 05:44 PM
 
I've been using Vim for text processing and would like to remove the EOL code in all my files (a grep function?) so that when used in another application they no longer stay at 72 spaces. ie Lines now wrap to the page. Thanks.
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jul 12, 2005, 06:35 PM
 
Assuming the files look something like this:
Code:
This is some text that gets cut off rather poorly. It has two line breaks between paragraphs.
The following script will clean up the line breaks in the middle of the sentences:
Code:
#!/usr/bin/ruby -ni.bak out = if $_ == "\n" $last == "\n" ? "\n" : "\n\n" else $_.chomp end print out $last = $_
It will save backups as <filename>.bak in case something goes wrong. Remove the ".bak" at the end of the shebang line if you don't want it to do that.
( Last edited by Chuckit; Jul 12, 2005 at 07:26 PM. )
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
jgift  (op)
Dedicated MacNNer
Join Date: Feb 2003
Status: Offline
Reply With Quote
Jul 13, 2005, 07:23 PM
 
The resposnible item in my .vimrc is:
" Set default textwidth
set tw=72


Do I use your source as a shell script and give it the text file name?

ie test.sh mytestfile.txt

Thanks!
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jul 13, 2005, 07:50 PM
 
Yep. It's actually a Ruby script, but both Panther and Tiger include Ruby by default, so it shouldn't make a difference unless you're using a very old OS version.

By the way, I don't use Vim much, but a Google suggests that you can tell it not to wrap with "set nowrap".
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
parallax
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Jul 14, 2005, 01:07 AM
 
If you just want to disable textwidth you can just use set tw=0

Depending on what you're editing, "undoing" the wrapping can be a harder issue. That ruby script will work above if it's something like paragraphs and text in LaTeX, but not well if it's code.
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jul 14, 2005, 02:34 AM
 
To be specific, it will work for anything where single newlines in the middle of text signal wrapping and multiple newlines signal intentional paragraph breaks. This isn't the case for a lot of code (in fact, it would ruin the script if you ran it on itself), but there's really no way around that without writing a parser for the particular language involved to determine whether or not a line break needs to be there.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
   
 
Forum Links
Forum 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 On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 03:20 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,