|
Moving files between Windows / DOS and Linux / Unix
Text files written on a Windows or DOS operating system use a carriage return character (ASCII decimal equivalent 13) followed by a line feed (ASCII decimal equivalent 10) as their line terminator, but on Linux, Unix and OS X systems, just the line feed character is used. And sometimes you'll find that there's just a carriage return character used - I've seen it this morning with a DreamWeaver generated Style sheet, for example.
If you're transferring text files around, you'll want / need to convert them in some way, but is you're transferring binary files (such as .jpg) , conversion will damage the content beyond redemption.
Here's a tiny utility that I use - a Perl program that converts a text file that's on a Unix / Linux / OS X box from an alien format to the local format.
#!/usr/bin/perl -p
s/\r\n?/\n/g;
Yes - that's it! Makes use of Perl's topicalisation and awk mode command line options. The source code with comments is available here. I called it cv, put it in a directory on my executable path, and made it executable ... and here's a test:
grahamellis$ od -c fiddle.txt
0000000 L i n e 1 \r \n L i n e 2 \r \n
0000020
grahamellis$ cv fiddle.txt > faddle.txt
grahamellis$ od -c faddle.txt
0000000 L i n e 1 \n L i n e 2 \n
0000016
grahamellis$
Other ways of converting ...
• if you transfer files through FTP in ASCII mode, the changes will be made during the transfer (and if you transfer a binary file in ASCII mode, you'll produce a damaged copy!)
• if you read files into certain utilities / editors, they'll convert the input for you silently and / or work in an alien mode. This applies to vim and wordpad, but notepad can't cope.
• Utilities dos2unix and unix2dos are available on some operating systems. (written 2006-12-30 09:16:48)
Associated topics are indexed under A101 - Web Application Deployment - Linux -An Introduction For Users
Some other Articles
Modernising from tables to cascading style sheetsSearch engine placement - long term strategy and successChristmas Season PicciesCopy multiple files - confusing error message from cpMoving files between Windows / DOS and Linux / UnixWell House Manor and Beechfield House, Hotels, MelkshamDates, times, clickable diarys in PHPPassing GET parameters through Apache mod_rewriteDate conversion - PHPFriends and family
|
2259 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46 at 50 posts per page
This is a page archived from The Horse's Mouth at
http://www.wellho.net/horse/ -
the diary and writings of Graham Ellis.
Every attempt was made to provide current information at the time the
page was written, but things do move forward in our business - new software
releases, price changes, new techniques. Please check back via
our main site for current courses,
prices, versions, etc - any mention of a price in "The Horse's Mouth"
cannot be taken as an offer to supply at that price.
Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).
|
|