I need to convert the text file to dos format (ending each line with 0x0d0x0a
, rather than 0x0a
only), if the file is in unix format (0x0a
only at the end of each line).
I know how to convert it (sed 's/$/^M/'
), but don't how how to detect the end-of-line character(s) of a file.
I am using ksh.
Any help would be appreciated.
[Update]: Kind of figured it out, and here is my ksh script to do the check.
[qiangxu@host:/my/folder]# cat eol_check.ksh
#!/usr/bin/ksh
if ! head -1 $1 |grep ^M$ >/dev/null 2>&1; then
echo UNIX
else
echo DOS
fi
In the above script, ^M
should be inserted in vi
with Ctrl-V
and Ctrl-M
.
Want to know if there is any better method.
test.txt: ascii text
, no matter what kind of end-of-line is used intest.txt
. It doesn't tell me if CRLF is contained or not. – Windbound