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

2022-09-12 15:15:06 浏览数 (1)

解决方法Solution

7z grep awk:

代码语言:javascript复制
7z l -slt lang.7z | grep "^Path = " | awk '{print $3}'
方法1方法1

7z grep sed:

代码语言:javascript复制
7z l -slt lang.7z | grep "^Path = " | sed 's/^Path= //g'
方法2方法2

以下为探索过程

引言Introduction

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

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

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

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

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

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

awk:

代码语言:javascript复制
7z l -slt lang.7z | grep "^Path = " | awk '{print $3}'

7z grep awk7z grep awk

sed:

代码语言:javascript复制
7z l -slt lang.7z | grep "^Path = " | sed 's/^Path= //g'

7z grep sed7z grep sed

0 人点赞