Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'I've always used zip and unzip...' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
I've always used zip and unzip...
Authored by: vajonez on Oct 22, '03 02:19:54AM
I've always used the following (in a file named fixascii):

#!/bin/sh
zip -qr foo.zip "$@" && unzip -aqo foo.zip && rm foo.zip

And then execute it as:

fixascii [files or directories to convert]

Which has the benefit over most of these other commands in that you can point it with impunity at an entire directory tree and it will process all the files in it and not corrupt any binaries that may happen to have a string of bits in them that look like a line-ending.

I've seen too many times where someone corrupted a ton of images and other binaries, when trying to fix line-endings on text files using dos2unix or tr in combination with find but failed to ensure that only text files were processed. Unzip figure out which files are ascii, converts them, and leaves the binaries alone.

BTW, it's the "-a" flag to unzip, that is causing the ascii files to have their lines endings converted.

[ Reply to This | # ]

I've always used zip and unzip...
Authored by: HotFusionMan on Jan 05, '09 02:49:45PM

Thanks! Couldn't resist optimizing this one a bit, though. :)

zip -qr0 foo.zip "$@" && unzip -aqo foo.zip && rm foo.zip

which does no compression and presumably will take less CPU time. Of course it requires more disk space....

I thought about factoring out the foo.zip into a variable but am too rusty in sh/bash syntax and have already spent too much time skimming through the bash man page. :)

I also thought about generating a (hopefully)-guaranteed unique temp filename rather than using foo.zip as is. I think you do that with $$ or similar.



[ Reply to This | # ]