get the text inside a zipped text file without extraction

To get the content of a zipped file, you can do unzip -p archive.zip file1.txt | less as said here

However, for that is for the case where you are "positioned" in the path where your .zip is. If you are not (for the case the command being executed in a shell script for example), I guess I would need to pass in the absolute paths for the .zip and the file, but a filename not matched: error is thrown.

For a .zip in the home directory I tried this commands:

unzip -p ~/archive.zip ~/archive.zip/file1.txt | less
unzip -p ~/archive.zip ~/archive/file1.txt | less

but I get the filename not matched: error.

How can I get the content of a txt file, without unzipping using absolute paths? (meaning not having to be in the specific directory of the .zip to run the command or to be able to perform that task form other path or a shell script)


The -p flag extracts files to pipe insted of unzipping into actual files. You don't need to use any additional path. Use this:

unzip -p ~/archive.zip file1.txt | less

I tested it in Centos 8:

enter image description here