How to stop new line conversion when zipping a Windows text file on a Unix machine - bash

I want to zip a windows .cmd file on an OSX server, using the zip command line tool.
templateName="Windows_Project_Template"
zip -r -T -y -9 "${templateName}.zip" $templateName
When the file is unzipped on a windows machine all the new line carriage returns are converted and so the text file comes out without any new line formatting on a windows machine. How can I work around this?
Thanks

While not a perfect solution (I can't find an option to handle everything as binary), you can force the \r\n with the --to-crlf option:
-l
--to-crlf
Translate the Unix end-of-line character LF into the MSDOS convention CR LF. This option should not be used on binary files. This
option can be used on Unix if the zip file is intended for PKUNZIP under MSDOS. If the input files already contain CR LF, this
option adds an extra CR. This is to ensure that unzip -a on Unix will get back an exact copy of the original file, to undo the
effect of zip -l. See -ll for how binary files are handled.
Be careful, if the file already contains \r\n you will get \r\r\n.

Related

Delete the input file after GhostScript finishes converting to PDF

Can someone show me how to use the PostScript deletefile operator to delete the input file after GhostScript finishes converting the input file to a PDF file.
This appears to work for me, first creating the PDF file, then setting the permissions on the input file, and finally deleting the input file.
"C:/Program Files/gs/gs9.55.0/bin/gswin64c.exe" -q -sDEVICE#pdfwrite
-o "C:/Temp/Temp_0001.pdf"
-f "C:/Temp/Temp_0001.ps"
--permit-file-all=C:/Temp/Temp_0001.ps
-c (C:/Temp/Temp_0001.ps) deletefile
NOTE: Since I had to switch to Unix-style path separators (even though I am running this on Windows) for the permit-file-all and the deletefile, I decided to use the same convention for both the output and input files as well. Windows seems to be OK with that, and the convention was uniformly used for all paths/files.

macOS How to read Pages/Numbers file in command line?

macOS How to read Pages/Numbers file in command line ?
I have userd 'cat'
cat /Users/administrator/Downloads/test.pages
but get:
????(??#?-QEQEQEQEQEQEQEQE?kYe??Ȍ?"8?,?9A?i;??1]?????=.SE[????Sqs-?,?iY??3]]QEQEQEQEQEQEQEQE??????(??(??(??(??(??(??(??(??(??(??????(??(??(??(??
addtional
I can use cat to watch .md file
Pages/Numbers files are .zip archives of binary files, not text files. In order to read them on the command line, you'll need a special tool, though I don't believe one exists at the moment

line break issue caused file corruption

I downloaded one zip file from the server using getstore() function in the perl script and unzipped the filed using Unzip method. Now if I try to access that file, I see below error.
ERROR:XXX file corrupted, CR found. Likely cause is file line endings
translated from Unix to CR+LF format
No such error was not seen when I manually download the file by clicking hyper-link and unzip it using windows extraction method. Could anybody please explain why it might be happening? Is there anyway we can access the corrupted file using some tool/application?
LWP::Simple's getstore writes to disk exactly what was received.
It's your browser that's "corrupting" the file. If you wish to perform the same "corruption" as your web browser, i.e. if you wish to convert DOS line endings to unix line endings, you can use the command line utility dos2unix.
Or you could modify your Perl script to get without storing, convert the line endings, and store the converted result.

ftp appends ^M to .Z file

I am doing ftp in binary mode and downloading some compressed_file.Z but I get compressed_file.Z^M and when I am using dos2unix it creates a new file with ^M removed but still when I try to uncompress it, I get error saying Corrupt Input or its not recognized as tar file etc. If I paste it in my windows machine using filezila, I am able to open it with 7Z. I have also used sed 's/^M$//' compressed_file.dmp.Z^M>compressed_file.dmp.Z but still it is corrupt file. Has someone faced similar issue?
It's likely that it's only your filenames that contains ^M at the end. You could rename them with:
for A in *.Z$'\x0d'; do
mv -i "$A" "${A%?}" # Remove -i to skip confirmation
done
Removing specification of any kind of mode say ASCII or BINARY etc solved my problem.

Compress command results in corrupted zip file

I have a script set up to rotate some log files in windows, and as part of the process I'd like it to automatically compress the rotated file. To do this I use the command
compress source.file destination.file.zip
However, if I try to open the file, I get the message "The Compressed (zipped) Folder is invalid or corrupted"
I've tried compress with -Z, and I get the same message. What am I doing wrong?
compress output is not ZIP file format compatible, it uses the LZW algorithm.
The only way to "open" a compressed file is with uncompress or gunzip.
Windows ports of common Unix commands, including compress and gzip/gunzip available here.
EDIT: To produce ZIP files from the command line in Windows, you can use something like 7-Zip, which includes a command line application (7z.exe). The Unix commands linked above also include zip.exe for manipulating ZIP files from the command line.

Resources