4

Basically we need to change the end of line characters for a group of files.

Is there a way to accomplish this with a batch file? Is there a freeware utility?

4
  • Advice from someone who has been fighting this for decades: don't. Do not convert data files between different formats, fix your programs to accept either format. Mar 30, 2010 at 19:09
  • The problem is with third-party tools that don't.
    – T.E.D.
    Mar 30, 2010 at 19:17
  • @T.E.D. The only way to win is to not use such tools. Mar 30, 2010 at 19:28
  • Does Oracle accept both formats? Mar 31, 2010 at 18:09

4 Answers 4

8

dos2unix

1
  • You'll probably want a regex with that like terminal$> dos2unix *.extension
    – rlb.usa
    Mar 30, 2010 at 18:59
2

It could be done with somewhat shorter command.

    find ./ -type f | xargs -I {} dos2unix {}
0

You should be able to use tr in combination with xargs to do this.

On the Unix side at least, this should be the simplest way. However, I tried doing it that way once on a Windows box over a decade ago, but discovered that the Windows version of tr was translating my terminators right back to Windows format for me. :-( However, I think in the interveneing decade the tools have gotten smarter.

0

Combine find with dos2unix/fromdos to convert a directory of files (excluding binary files).

Just add this to your .bashrc:

DOS2UNIX=$(which fromdos || which dos2unix) \
  || echo "*** Please install fromdos or dos2unix"
function finddos2unix {
# Usage: finddos2unix Directory
find $1 -type f -exec file {} \; | grep " text" | cut -d ':' -f1 | xargs $DOS2UNIX
}

First, DOS2UNIX finds whether you have the utility installed, and picks one to use

Find makes a list of all files, then file appends the ": ASCII text" after each text file.

Finally, grep picks the text files, Cut removes all text after ':', and xargs makes this one big command line for DOS2UNIX.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.