Any command we can use to convert windows file to

2019-09-17 15:57发布

问题:

I don't want to use dos2unix tool. I want to use command in Ubuntu terminal to convert Windows file to Unix file. Is that possible. I have looked through other articles and tried those commands but none working. Anyone can help?

回答1:

You can use tr to remove carriage returns like this:

tr -d '\r' < WindowsFile > UnixFile

You can use

cat -vet WindowsFile

to see if there are carriage returns in your file and they'll show up as ^M



回答2:

I want to use command in Ubuntu terminal to convert Windows file to Unix file.

dos2unix path/to/file/to/convert

I don't want to use dos2unix tool.

alias notdos2unix=dos2unix

notdos2unix path/to/file/to/convert


回答3:

For Ubuntu(and Debian) you can use the tofrodos package.

sudo aptitude install tofrodos
fromdos file.txt # converts the file to UNIX line-endings
todos   file.txt # converts the file to Windows line-endings

OSX (being a derivative of UNIX) should have the same line-endings as UNIX.

If you're on Windows, you can find tofrodos binaries here.

If you're on a Mac, you can use the brew package manager and install the tofrodos on OSX.



标签: linux perl