首页 > 解决方案 > 如何从 unzip -l 的输出中获取特定路径

问题描述

我需要在 .app 文件夹之后提取 Info.plist 文件的路径。

$ unzip -l test.ipa | grep Info.plist
258  05-25-2018 11:52   Payload/test.app/CDVLaunchScreen.storyboardc/Info.plist
2197  05-25-2018 11:52   Payload/test.app/Info.plist

问题是 .app 文件夹在每个 .ipa 文件中的名称都不同。我不能 grep Payload/test.app/Info.plist。我试过了:

$ unzip -l test.ipa | grep Payload/*.app/Info.plist
$ unzip -l test.ipa | grep "Payload/..app/Info.plist"

什么都没有。

正确的 grep 参数如何?另外,我如何只提取路径(Payload/test.app/Info.plist)而不是整行(2197 05-25-2018 11:52 Payload/test.app/Info.plist)?

标签: regexbashgrepunzip

解决方案


如果您不确定是否所有路径都以 开头Payload,请尝试

unzip -l test.ipa | grep -P '(?<=\s)\S*Info.plist'

匹配之前的所有非空白字符Info.plist


推荐阅读