I want to get the number of files (included directories) contained in the root of a 7z archive, but the 7z command on Linux don’t bring a simple way to only get the number and noting else.
For example I have the 7zarchive.7z file witch contain archive.tar and archive.gzip. Then, 7z l 7zarchive.7z print me the following verbose lines:
7-Zip 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
p7zip Version 9.20 (locale=fr_FR.UTF-8,Utf16=on,HugeFiles=on,2 CPUs)
Listing archive: 7zarchive.7z
--
Path = 7zarchive.7z
Type = 7z
Method = LZMA
Solid = +
Blocks = 1
Physical Size = 495
Headers Size = 184
    Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2016-03-14 22:43:10 ....A        20480          311  archive.tar
2016-03-14 23:04:01 ....A          163               archive.gzip
------------------- ----- ------------ ------------  ------------------------
                             20643          311  2 files, 0 folders
In the right bottom, you can see “2 files, 0 folders”, so I want to get the sum of number of folders and number of files.
For this, I try the flowing hideous command :
bash
7z l 7z l *.7z  | tail -1 | sed -e 's/.* \([0-9]*\) files\, \([0-9]*\) folders/\1 \2/' -e 's/\([0-9]*\) \([0-9]*\)/\$(( \1 + \2))/'  | tail -1 | sed -e 's/.* \([0-9]*\) files\, \([0-9]*\) folders/\1 \2/' -e 's/\([0-9]*\) \([0-9]*\)/\$(( \1 + \2))/'
- tailextract the last line;
- The first sedexpression extract the numbers before the words “files” and “folders”.
- The second sedexpression formate it to be printed like this$(( <first number> + <second number>)).
So, I really obtain the output $(( 2 + 0)), but I want it to be executed to get only the result (2) and not the command to calculate the result.
So, there is a way to do this, or, at list, a more simple way to get the number of files contained by a 7z archive?
