1

I was working with a project that was saved in linux I opened it in a windows IDE and the strange thing is that it inserted break lines in all .java .jsp and other text files

I like to remove all those empty lines recursively at the root directory of the project.

Does anybody have some shell script that can I run to change these files?

Thanks in advance, André.

2
  • What Windows IDE are you using? Commented Oct 4, 2010 at 18:26
  • I forgot to tell, I'm using NetBeans. Commented Oct 4, 2010 at 18:43

4 Answers 4

2

You might just need to run dos2unix on the files. Pass it through a hex viewer to see if the line-endings are 0D 0A (CR/LF) or are actually two newlines or something else. If the former, dos2unix will work. Something like:

find . -name \*.java -exec dos2unix \{\} \;

From your root source directory. Test first, make backups, etc.

Sign up to request clarification or add additional context in comments.

2 Comments

It sounds like he's in the converse situation: his source is from a Linux system (lines terminated with LF) and now he's on Windows. Is there a unix2dos?
There is, but no guarantee it's available on Windows. I'd need more information to know exactly what's going on (what is "it", what were the binary changes that were made to the files, etc).
1

Which Windows IDE are you using? Is this Eclipse? If yes.

Window -> Preferences -> Java -> Code Style -> Clean Up -> Edit -> Remove Trailing whitespace

Hopefully this will work

1 Comment

I'm using NetBeans, it have a similar function Menu: Source -> Remove Trailing whitespace... But it doesn't remove the empty lines.
0

On a sidenote, not directly being an answer to your question (it seems like there already are good answers), I would recommend, if possible, to use a bit of time to uniformly setup your IDE environments so that they are compatible.

I have great experience in using Eclipse as it is available for all major OS platforms, and has the option of saving essential project settings in whichever repository you are using, thus enabling you to have identical setups so that for example line breaks are handled properly.

Also, to ensure everybody has the same Eclipse configuration, plugin versions, even basic workspace configurations, I strongly recommend using Eclipse configuration management tools like Yoxos, as it enables you to specifically configure a Eclipse configuration per project, and distribute said configuration in a simple XML-based file associated with the Yoxos Launcher program which handles dependencies, updates etc.

I have been involved in quite a few projects thus far, and even in teams where we are developing from Linux, Windows and Mac OS X, there are no (or well as minimal as possible anyway) problems with configurations, line breaks, plugin versions, etc. due to the extra effort in streamlining the IDE setups.

Comments

0

You might want to see if you can configure your IDE/editor to deal with the files instead of converting them. If you use source control, changing all your line endings will flag every line in every file as "modified", and that will make it difficult (if not impossible) to track changes if/when you migrate the code back to your Linux system.

2 Comments

This project it's not on source control (for a while), but as soon as I fix this double space problem I'll import it to SVN.
others answers none of them worked, because when I take a look with a hex editor the break lines in files are mixed (OD) and (ODOA) in the same files, so unix2dos didn't solve, and Remove Trailing whitespace neither. I also tried run shed command but it didn't help either.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.