I've adjusted my script so it won't accidentally drop lines we need.
awk '{print $1}' should drop any "link redirections".
#!/bin/sh
OUTPUT_DIR=/tmp/tcz-list
mkdir -p $OUTPUT_DIR
strip_path() {
awk 'BEGIN {FS="\n";RS=""} {
for (i=1;i<NF;i++) {
if ($(i + 1) !~ $i"/") print $i
}
}' < /dev/stdin
}
for TCZ in $@; do
unsquashfs -l $TCZ | grep 'squashfs-root/' | cut -d '/' -f 2- | awk '{print $1}' | strip_path > ${OUTPUT_DIR}/"$(basename $TCZ)".list
done
Some explanations:
Each (awk) loop, I take two lines and compare the differences.
If the patterns does not look like something below a directory, then print the line we're checking.
For instance:
tc@box:/tmp$ unsquashfs -l svn.tcz | grep 'squashfs-root/' | cut -d '/' -f 2- | awk '{print $1}'
usr
usr/local
usr/local/bin
usr/local/bin/svn
usr/local/bin/svnadmin
...
In the awk function:
if ($(i + 1) !~ $i"/") print $i
loop1: if (usr/local !~ usr/) ==> "
usr/local" contains "
usr/" --> skip
loop2: if (usr/local/bin !~ usr/local/) ==> "
usr/local/bin" contains "
usr/local/" --> skip
loop3: if (usr/local/bin/svn !~ usr/local/bin/) ==> "
usr/local/bin/svn" contains "
usr/local/bin/" --> skip
loop4: if (usr/local/bin/svnadmin !~ usr/local/bin/svn/) ==> "
usr/local/bin/svnadmin" does not fit "
usr/local/bin/svn/"
--> print "usr/local/bin/svn"And so on ~
By using this technique, empty directory can be preserved.
P.S.
I flip the listing order back to normal, it's no longer in reverse.
P.P.S.
IIRC, the leading slash '/' of "
/usr/local/bin/svn" should be removed, no
?