解决方法Solution
7z grep awk:
代码语言:javascript复制7z l -slt lang.7z | grep "^Path = " | awk '{print $3}'
7z grep sed:
代码语言:javascript复制7z l -slt lang.7z | grep "^Path = " | sed 's/^Path= //g'
以下为探索过程
引言Introduction
使用7zip命令行工具7za/7z时遇到一个问题,只列出归档内容的文件名? How to use 7zip command line version tool for listing only filenames?
低调的-slt开关 -slt switch with a low profile
让我试试看. Let's have a try.
代码语言:javascript复制7z l -slt lang.7z | more
这样一行行输出文件信息,空行分隔不同文件,十分利于grep,awk提取文件名等信息. This command displays file info one item per line such as path, size, etc. And an empty line is displayed between two different files as separator. It is now more convenient for grep and awk to parse.
把输出重定向到grep "^Path = "命令.Let's redirects the output to command grep "^Path = " with a pipe '|'.
awk:
代码语言:javascript复制7z l -slt lang.7z | grep "^Path = " | awk '{print $3}'
sed:
代码语言:javascript复制7z l -slt lang.7z | grep "^Path = " | sed 's/^Path= //g'