Monday, April 6, 2015

Converting ^M linebreak with sed

To convert ^M linebreaks that appear in your file, if you read it with vi or less, to a unix type linebreak use sed command:

sed -e 's/\r/\n/g' file.txt > file.txt_sed

which will substitute globally ^M with \n

(this work if you transfer a file from Mac OS to Linux since, /r is a Mac linebreak, for the DOS type of files use: 

sed -e 's/\r\n/\n/g' file.txt > file.txt_sed

since /r/n is a linebreak in DOS files).

No comments:

Post a Comment