zl程序教程

您现在的位置是:首页 >  其它

当前栏目

slt开关:7z仅列出文件名|slt:7z lists only filenames|grep+awk/sed

Only 文件名 awk grep sed 列出 开关 7z
2023-06-13 09:12:25 时间

解决方法Solution

7z+grep+awk:

7z l -slt lang.7z | grep "^Path = " | awk '{print $3}'
方法1

7z+grep+sed:

7z l -slt lang.7z | grep "^Path = " | sed 's/^Path= //g'
方法2

以下为探索过程

引言Introduction

使用7zip命令行工具7za/7z时遇到一个问题,只列出归档内容的文件名? How to use 7zip command line version tool for listing only filenames?

7z不好看也不好处理的输出的文件信息分隔不定,badly separated info listed by 7z

低调的-slt开关 -slt switch with a low profile

这个'detailed technical information'是个什么意思??what does 'detailed technical information' mean at all??

让我试试看. Let's have a try.

7z l -slt lang.7z | more
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 '{print $3}'提出第三列或者sed 's/^Path = //g'去掉"Path = "就可

awk:

7z l -slt lang.7z | grep "^Path = " | awk '{print $3}'

7z+grep+awk

sed:

7z l -slt lang.7z | grep "^Path = " | sed 's/^Path= //g'

7z+grep+sed