Trying to unzip a file inside sub directory getting error: caution: filename not matched

Posted on

Problem :

So I have a script that iterates over zip files, lists their content with unzip -l $filename, and looks for matches to pattern (.*)report.xml, in this case yields test0report.xml

But when it tries to unzip using unzip -j $filename, I get caution: filename not matched: test0report.xml

I stopped and tried manually on a file which lists:

7285 2018-05-04 13:34 test0report.xml

Then doing

unzip -j test0report.xml

Gives me the error caution: filename not matched: test0report.xml

I tried calling with \ to escape it, then same error but saying test0report.xml instead.

I tried everything like , or /, or // so I dont think this is backwards slash escaping issue.

Please help.

Solution :

I have recreated the issue in my Kubuntu. The file name was literally test0report.xml and when I did

unzip -j test0\report.xml

unzip returned filename not matched: test0report.xml although the string it got should match, I think.

The tool supports some wildcards. I was able to unzip the file with this command:

unzip -j 'test0?report.xml'

A bug? I guess you have to add some logic to your script or just to unzip by hand whenever such (hopefully rare) situation occurs again. Or take advantage of these wildcards supported by unzip and instead of matching (.*)report.xml in the script let unzip do the job:

unzip -j '*report.xml'

Leave a Reply

Your email address will not be published. Required fields are marked *