If you are working in teams using different operating systems, it could happen, that you get files with unsuitable linefeeds in it. For me as a Linux user the bad guys are normally CRLF’s (Carriage Return and Line Feed @see https://en.wikipedia.org/wiki/Newline).
To just convert the CRLF’s in a single file to LF you can use the following command:
$> dos2unix filename
The inverse operation that converts LF’s to CRLF’s is:
$> unix2dos filename
The following code snippet shows how to convert linefeeds for all files in a folder:
$> find . -type f -print0 | xargs -P 4 -0 -n 1 dos2unix
What does this command do?
- searches for all files (-type f) in the current folder (.)
- pushes the filenames into standard output (with a tailing null character -> no Problems with whitespace or even linebreaks in filename)
- which is piped into xargs that is informed about the terminating null character (-0) => so knows how to interpret the input properly
- xargs only reads the first given argument (here: the filename) from the input (-n 1)
- xargs pushed the filename to dos2unix that converts every file given
- The -P 4 – parameter tells xagrs to spread the different file conversion commands over at maximum four processes. Which is good to process a huge amount of files.