Convert DOS text files to UNIX text files
I've got a lot of text files (source code) that I created in Windows, but then I moved them to Linux. Some of them retained their DOS text file format, but I would like them all to be in UNIX format. Is there a fast way to convert 50 or so files to UNIX? The way I've done it before is:
1) rename the file 2) create a new file with the old name 3) paste the text into it 4) delete the old file I would be halfway willing to do that for the rest of them, except they all have at least one hard link, therefore they must be converted in place to retain the same inode. Thanks. ta0kira |
Using tr is what i'd use to convert the files
tr -d '\r' < dosfile > unixfile Retaining the same inode may require the use of an intermediate file. HTH Mad |
I don't know about the hard link part but you may have success using tr to get rid of the \015 . After that is done, you could just move the new file back to the old file.
For example: Code:
tr -d '\015' file.txt > file1.txt |
Maybe something like ...
Code:
sed -e 's/.$//' dosfile.txt > unixfile.txt |
dont need the sed or tr
There is tiny little program for it (which does basically the same as sed and tr )
dos2unix and of course unix2dos read the manpages for details. Programs are usually located in /usr/bin (if you installed it there of course) and present in most distributions. |
Thanks. I think Slack10 uses 'fromdos' which sounds like it does the same thing. I'll try that and let you know. Hopefully it leaves my already-UNIX files alone.
ta0kira |
I tried 'fromdos' which worked fine, except one or two already-UNIX were messed up. I had them backed up though. I had to use a temp file to keep the files in the same place.
ta0kira |
I needed to convert an entire directory of files from dos to unix format, so I have used the following combination, inspired by madluther's post.
Code:
find | sed -e "s/\(.*\)/tr -d \'\\\r\' < \1 > __\1/g" | sed -e "s/__\.\//\.\/__/" | /bin/sh -it gives warnings about directories -it will not work with any files in sub-directories -probably any files starting with '__' can be badly affected |
All times are GMT -5. The time now is 10:51 PM. |