0

So that's the question...perhaps there's a regular expression for this? Just to be clear, I don't want to remove ALL newlines and bunch all of the code together, only the extras. I'm not familiar with how to construct regexes, so any help is greatly appreciated!

And here's the explanation as to why:

I was obviously ignorant of the troubles the following situation could cause, so you know I'm now fully aware of that! I've submitted c# code on a mac to perforce, which originally came from windows. Now I've updated those source files on my PC, and their line endings are now messed up, with VS 2008 giving me a compiler error, telling me to fix my mac line endings. I found the Stripem VS add-in, which fixes the compile error, but the code looks terrible, with tons of extra lines.

  • What do you mean by "extra empty lines"? Just look at your text file with a binary editor or so, to figure out what the character (or sequence of characters) is that you want to remove. – Domi Dec 06 '13 at 17:00
  • Might be you need to use dos2unix utility: http://waterlan.home.xs4all.nl/dos2unix.html – alex Dec 06 '13 at 17:45
  • @Domi - I mean lines that weren't there previously on the original PC version of the file. Basically I think what it did was add a CR (mac) for every CRLF. So how to identify this with regex? – Ramon Johannessen Dec 06 '13 at 19:27
  • @alex - I tried using unix2dos, but it didn't change anything. There were no output errors.. – Ramon Johannessen Dec 06 '13 at 19:29
  • @RamonJohannessen - It should be a command like: Convert c.txt from Mac to Unix ascii format. "dos2unix -c mac c.txt b.txt" - http://linuxcommand.org/man_pages/dos2unix1.html ; And then you can use unix2dos command to convert it to Windows format - http://www.linuxcommand.org/man_pages/unix2dos1.html – alex Dec 06 '13 at 20:07
  • @alex - Ah OK, I wasn't doing the first conversion to unix, now it does change the file, but it doesn't remove all the added new lines. I found CodeMaid - http://visualstudiogallery.msdn.microsoft.com/76293c4d-8c16-4f4a-aee6-21f83a571496/?SRC=VSIDE, which does fairly well at cleaning up, not perfect, but the best I've found so far. – Ramon Johannessen Dec 06 '13 at 21:21

2 Answers2

0

For the regex approach, see if you can match one or both of \r or \n .

Community
  • 1
  • 1
DavidRR
  • 15,000
  • 17
  • 89
  • 169
  • Yeah, I was able to fix one file completely by matching \x0d\x0a, replacing it with nothing. I tried another file and it just put everything in one line. I'm not sure what's different at the moment, I'll have to do some digging. – Ramon Johannessen Dec 06 '13 at 21:29
0

I don't know what ending of line mac's are using... but if it is \n and \r this could help:
remove all \r or replace it with \n, then replace multiple \n with one \n.

You could use Notepad++, it has nice conversion between EOL Windows/UNIX/Mac.

FYI: I use VS2012 and there is build-in mechanism for this kind of things:
File -> Advanced Save Option...
And then you choose encoding and line endings.

Carnifex
  • 503
  • 3
  • 8