2

I could find the way to print zip entries' list and forward to a txt file.

unzip -l my.zip | awk '{print $4}' > my.txt

When I open the file my.txt in windows' notepad the line delimiters ignored and all lines renders in a single line.

How can I make those piped lines to have appropriate line delimiters?

2 Answers 2

2

The output of each awk processed line is terminated in a linefeed (\n) which is the Unix/Linux standard. Windows/DOS expects a carriage return followed by a linefeed to mark the end of the line (\r\n). notepad will display all Linux generated files as you are currently seeing them.

To resolve, pipe the output of awk through the unix2dos command, which converts ns to \r\ns for you:

unzip -l my.zip | awk '{print $4}' |unix2dos > my.txt

Alternatively, try telling awk to output \r\n at the end of each line using the ORS variable:

unzip -l my.zip | awk -v ORS='\r\n' '{print $4}' > my.txt

To list without header and footer:

unzip -l my.zip | awk -v ORS='\r\n' '{print $4}' | tail -n +4 | head -n -2 > my.txt

Or

Alternatively, use zipinfo -1 <zip file> (number 1, not letter l) to list files without a header and footer. You may still need to pipe it through unix2dos. Useful only if zipinfo is available in CygWin.

1
  • Do you have any idea how to suppress headers and footers of unzip -l command? Thanks.
    – Jin Kwon
    Aug 9, 2014 at 11:25
0

I managed to convert the output file's line delimiters to dos style with unix2dos.

$ unix2dos my.txt
unix2dos: converting file cdc_1.1.jar.txt to DOS format...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.