C0de_Hard
C0de_Hard

Reputation: 72

Unzip a file zipped in Unix using 7zip

My target is to send a file created by Unix process to myself as an excel file. So I have used the below commands to achieve it.

tr -d '\t' < PROGRAM_CREATED_FILE | sed -e 's/\\//g' | awk 'BEGIN{FS=">"; OFS="\t"} '{$1=$1}1' > file.xls
gzip -9 file.xls
echo "test mail" | sendxchange -a "file.xls.gz" -s "Report" my_mail_id

After receiving the file on my mail box, I save it in Windows machine. I try to extract the archive using 7zip. It attempts to extract and says Data error in file.xls. File is broken

Need help on this.

Thanks

Upvotes: 0

Views: 606

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207465

Your compressed file is binary rather than the ASCII that Mail expects to send. You can either uuencode it or base64-encode it prior to sending, like this:

gzip -9 < file.xls | uuencode -m file.xls.gz > file.xls.gz
... sendxchange -a "file.xls.gz" ...

Using the -m above gives base64 encoding, and leaving it out results in uuencoding.

At the Windows end, you would need to decode the file again - for which you can use Microsoft's certutil tool (if you used base64 encoding), or the Unix utilities from SourceForge.

When transferring via FTP, be sure to set BIN mode first, else you may transfer in ASCII mode which is bad for binary files since it converts certain line-ending characters to the stupid Windows CR/LF combination and that may appear in your binary file an get converted - which is not what you want.

Upvotes: 1

Related Questions