30

I have 348 zip files and I want to find a file that is in one of the zip files, unzip -l doesn't work with wild cards?

How can I list content of all .zip files and grep through the merged list of all files contained in the zips?

4 Answers 4

18

Using zipinfo is a fine solution here. However, in general whenever you want to apply a command to a list of files and the command doesn’t accept a list of files, you can use a for loop:

for file in *.zip; do
    unzip -l "$file"
done \
| grep "\.zip\|setup"

If the file you are searching for has spaces in it like: your file, in the grep regular expression you need to escape every space with a backslash like grep "\.zip\|your\ file".

3
  • Works perfectly the only problem is that it doesn't show the name of the zip, Commented Oct 5, 2012 at 15:16
  • I edited you post and added regular expression to display also the filename where setup is found, +1 and accept Commented Oct 5, 2012 at 15:23
  • Oh yes, I’d forgotten the quotes around the argument to unzip, how embarrassing. Commented Oct 6, 2012 at 8:58
13

You can use zipinfo. It is included in the default Ubuntu installation. Check the manual page for more info.

For example, to look for a pattern setup in a bunch of zip files in current directory, use this command:

find ./ -iname *zip 2> /dev/null -print0 | xargs -0 zipinfo | grep setup
6
  • I get a caution: filename not matched: case1.zip... caution: filename not matched: case348.zip for every zip, tested on two Ubuntu OSs, 11.10 and 12.04. Commented Oct 6, 2012 at 5:24
  • @EduardFlorinescu Try the updated answer. Though the answer was working for me
    – Anwar
    Commented Oct 6, 2012 at 5:39
  • the problem is that the file might contain that setup and it puts the same error, although it works like this: zipinfo -l * | grep "setup" Commented Oct 6, 2012 at 5:42
  • I edited the answer. I think it is more robust now
    – Anwar
    Commented Oct 6, 2012 at 5:45
  • 1
    Thanks, +1 for effort, but still it will not work if zip file has spaces in its name. Commented Oct 6, 2012 at 5:48
7

To list the files in a zip archive you can use the following command.

unzip -l

To grep a compressed archive you should use the compressed archive utilities built to work with that type of archive format.

For zip archives:

zipgrep --help  
usage: zipgrep [egrep_options] pattern zipfile [members...]
Uses unzip and egrep to search the zip members for a string or pattern.

For tar archives:

zgrep --help
Usage: /bin/zgrep [OPTION]... [-e] PATTERN [FILE]...
Look for instances of PATTERN in the input FILEs, using their
uncompressed contents if they are compressed.

OPTIONs are the same as for 'grep'.

There are a few other tools that work with archives as well. You can pipe the out put into grep to do the same thing.

zcat
zcat my.archive.zip | grep "some text"

Or you can use the search functionality of these tools

zless
zmore
2

Here's a dash script (for Linux) for searching inside archive files:

Simply call the script with no parameters and the script will prompt for the necessary input:

#!/bin/dash
## Supported shells: dash, bash, zsh, ksh

GetOSType () {
    #$1 = returns the type of the current operating system:
        
    case "$(uname -s)" in
    *"Linux"* )
        eval $1="Linux"
        ;;
    *"Darwin"* | *"BSD"* )
        eval $1="BSD-based"
        ;;
    * )
        eval $1="Other"
        ;;
    esac
}

TestIfFileIsText () {
    #$1 = input file path
    #$2 = returns "true" if the input file is text, "false" otherwise
    
    result="false"
    eval current_file=\"\$$1\"
    current_file_mime_type="$(file -bL --mime-encoding "$current_file" 2>/dev/null)"
    case "$current_file_mime_type" in
        *"ascii"* | *"utf"* )
            result="true"
        ;;
    esac
    eval $2=\"\$result\"
}

ExtractFirstAndLastPathComponent () {
    #$1 = input path
    #$2 = returns the first path component
    #$3 = returns the last path component
    
    eval current_path="\"\$$1\""
    
    first_path_component=""
    last_path_component=""
    
    if [ -n "$current_path" ]; then
        #Remove trailing '/' characters:
        while [ ! "${current_path%"/"}" = "$current_path" ]; do
            current_path="${current_path%"/"}"
        done
        
        if [ -z "$current_path" ]; then
            eval current_path=\"\$$1\"
        fi
        
        last_path_component="${current_path##*"/"}"
        first_path_component="${current_path%"$last_path_component"}"
    fi
    
    eval $2="\"\$first_path_component\""
    eval $3="\"\$last_path_component\""
}

GetFileEncoding () {
    #$1 = input file path
    #$2 = returns the file encoding
    
    eval file_to_test=\"\$$1\"
    
    GetFileSizeInBytes file_to_test file_to_test_size_in_bytes
    
    #Get file mime encoding:
    if [ -d "$file_to_test" ]; then
        result="directory"
    elif [ ! "$file_to_test_size_in_bytes" -eq "0" ]; then
        file_mime_type="$(file -bL --mime-encoding "$file_to_test" 2>/dev/null)" || { file_mime_type="undetermined"; }
        case "$file_mime_type" in
            *"binary"* )
                #Only binary files containing the NULL character (^@) are considered binaries in this script:
                (cat -v "$file_to_test" | sed "/\^@/i'\^@'\$NL2") | { grep -q "\^@"; } && result="binary" || result="text"
            ;;
            *"ascii"* | *"utf"* )
                result="text"
            ;;
            * )
                result="undetermined"
            ;;
        esac
    else
        result="text"
    fi
    eval $2=\"\$result\"
}

GetFileSizeInBytes () {
    #$1 = the input file path
    #$2 = returns the input file size
    
    eval file="\"\$$1\""
    [ -z "$OS_TYPE" ] && GetOSType OS_TYPE
    if [ "$OS_TYPE" = "Linux" ] || [ "$OS_TYPE" = "Other" ]; then
        file_size_in_bytes="$(stat -c %s -- "$file")" 2>/dev/null || { file_size_in_bytes="-1"; }
    else
        file_size_in_bytes="-1"
    fi
    eval $2="$file_size_in_bytes"
}

PrintErrorMessage () {
    #Prints the total string parameters received by this function as a single error message:
    
    printf '\n%s\n' "${@}">&2
}

PrintErrorMessageAndSetError () {
    #Prints the total string the parameters received by this function as a single error message and sets the <error> variable to "true":
    
    printf '\n%s\n' "${@}">&2
    error="true"
}

trap1 () {
    #Calls the 'CleanUp' function after pressing "CTRL + C / CTRL + Z" and ends all the processes started by this script:
    
    printf "\n""Aborted.\n">"$print_to_screen"
    
    CleanUp
    
    #kill all children processes, suppressing "Terminated" message:
    kill -s PIPE -- -$$ 2>/dev/null
    
    exit
}

CleanUp () {
    #Removes temporary generated files and restores CTRL + C / CTRL + Z and other settings to their original role (i.e. as before running this script):
    
    if [ -n "$TEMPORARY_EXTRACT_PATH" ] && [ -n "$output_dir" ]; then
        rm -R -f "$output_dir/TEMP_EXTR_FOLDER/"*
    fi
    
    #Restore "INTERRUPT" (CTRL + C) and "TERMINAL STOP" (CTRL + Z) signals:
    trap - INT
    trap - TSTP
    
    #Clear the title:
    printf "\033]0;%s\007" "">"$print_to_screen"
    
    RestoreIFS initial_IFS

}

StoreIFS () {
    #Stores the IFS's variable value to the specified $1 variable:
    
    eval $1="\"\$IFS\""
}

RestoreIFS () {
    #Restore the IFS variable to the specified $1 variable value:
    
    eval IFS="\"\$$1\""
}

GetModifiedFileDateFull () {
    #$1 = the input file path
    #$2 = returns input file modified date
    
    eval input_file=\"\$$1\"
    [ -z "$OS_TYPE" ] && GetOSType OS_TYPE
    {
        if [ "$OS_TYPE" = "Linux" ] || [ "$OS_TYPE" = "Other" ]; then
            current_modified_date_full="$(stat -c "%y" "$input_file")" || { current_modified_date_full="-1"; }
        fi
    }||{
        current_modified_date_full="-1"
    }
    eval $2=\"\$current_modified_date_full\"
}

GetModifiedFileDateSSE () {
    #$1 = the input file path
    #$2 = returns input file modified date - Seconds Since Epoch
    
    eval input_file=\"\$$1\"
    [ -z "$OS_TYPE" ] && GetOSType OS_TYPE
    {
        if [ "$OS_TYPE" = "Linux" ] || [ "$OS_TYPE" = "Other" ]; then
            current_modified_date_SSE="$(stat -c "%Y" "$input_file")" || { current_modified_date_SSE="-1"; }
        fi
    }||{
        current_modified_date_SSE="-1"
    }
    eval $2=\"\$current_modified_date_SSE\"
}

GenerateMatchedFilesArrays () {
    #Generates matched <ARCHIVE PATHS> array and for each path: <MODIFIED DATE SECONDS SINCE EPOCH>, <MODIFIED DATE (LOCAL TIME)>, <SIZE IN BYTES> - arrays:
    
    IFS='
'
    i=0
    cd "$initial_dir"
    
    archive_type_1='.zip'
    archive_type_2='.tar.bz2'
    archive_type_3='.tar.xz'
    archive_type_4='.tar.gz'
    archive_type_5='.7z'
    archive_type_6='.rar'
    archive_type_7='.bz2'
    archive_type_8='.xz'
    archive_type_9='.gz'
    archive_type_10='.tgz'
    archive_type_11='.tar'
    archive_type_0="11"
    
    find_commands_0="9"
    extract_to_screen_commands_1="unzip -q -c \"\$file2\" $total_in_archive_file_path_filters"
    extract_to_screen_commands_2="tar -xOjf \"\$file2\" --wildcards $total_in_archive_file_path_filters"
    extract_to_screen_commands_3="tar -xOJf \"\$file2\" --wildcards $total_in_archive_file_path_filters"\
    extract_to_screen_commands_4="tar -xOzf \"\$file2\" --wildcards $total_in_archive_file_path_filters"
    extract_to_screen_commands_5="7z e \"\$file2\""
    extract_to_screen_commands_6="unrar p \"\$file2\""
    extract_to_screen_commands_7="bzip2 -dc \"\$file2\""
    extract_to_screen_commands_8="xz -dc \"\$file2\""
    extract_to_screen_commands_9="gzip -dc \"\$file2\""
    extract_to_screen_commands_10="tar -xOzf \"\$file2\"" ## ERROR: NO OUTPUT GENERATED (LINUX)
    extract_to_screen_commands_11="tar -xOf \"\$file2\"" ## ERROR: NO OUTPUT GENERATED (LINUX)
    extract_to_screen_commands_0="11"
    
    for current_search_path in $(eval find \"\$search_path\" -prune -exec printf "%s\\\\n" {} + ); do
        
        if [ ! -d "$current_search_path" ]; then
            ExtractFirstAndLastPathComponent current_search_path fpc_current_search_path lpc_current_search_path
            cd "$initial_dir"; cd "$fpc_current_search_path"; current_search_path="$PWD/$lpc_current_search_path"
            for j in $(GenerateSequence 1 $archive_type_0); do
                eval current_archive_type="\"\$archive_type_$j\""
                eval find_commands_$j="\"find \\\"\\\$current_search_path\\\" -type f -name \\\"*$current_archive_type\\\"\""
            done
        elif [ -d "$current_search_path" ]; then
            cd "$initial_dir"; cd "$current_search_path"; current_search_path="$PWD"
            for j in $(GenerateSequence 1 $archive_type_0); do
                eval current_archive_type="\"\$archive_type_$j\""
                eval find_commands_$j="\"find \\\"\\\$current_search_path/.\\\" -type f -name \\\"*$current_archive_type\\\"\""
            done
        fi
        
        for file1 in $(\
            { \
            j=0;\
            for l in $(GenerateSequence 1 $find_commands_0); do \
                eval current_find_command=\"\$find_commands_$l\"; \
                eval current_extract_to_screen_command=\"\$extract_to_screen_commands_$l\"; \
                eval current_archive_type=\"\$archive_type_$l\"
                
                PrintJustInTitle "Step 1: Finding $current_archive_type archive files..."; \
                
                GenerateMatchedFilePaths 1|uniq -d;\
                j=0;\
                
                PrintJustInTitle "Step 2: Finding $current_archive_type archive files..."; \
                
                GenerateMatchedFilePaths 2|uniq -u;\
            done; \
            }|sort --numeric-sort;\
            PrintJustInTitle "Preparing to store necessary file info..."; \
        ); do
            found="false"
            previous_file_path="$current_file_path"
            current_file_path="$file1"
            if [ -z "$previous_file_path" ]; then
                previous_file_path="$current_file_path"
                found="true"
            else
                if [ ! "$current_file_path" = "$previous_file_path" ]; then
                    found="true"
                fi
            fi
            
            if [ "$found" = "true" ]; then
                i=$(($i + 1))
                PrintJustInTitle "Storing necessary file info: file $i..."
                eval current_file_path=\"\$file1\"
                eval archive_paths_$i=\"\$current_file_path\"
                GetModifiedFileDateSSE current_file_path current_file_modified_date_SSE
                eval file_modified_dates_SSE_$i=\"\$current_file_modified_date_SSE\"
                GetModifiedFileDateFull current_file_path current_file_modified_date_full
                if [ ! "${current_file_modified_date_full%"."*" "*}" = "$current_file_modified_date_full" ]; then
                    current_file_modified_date_full_part1="${current_file_modified_date_full%"."*" "*}"
                    current_file_modified_date_full_part2="${current_file_modified_date_full#$current_file_modified_date_full_part1"."*" "}"
                    current_file_modified_date_full="$current_file_modified_date_full_part1$current_file_modified_date_full_part2"
                fi
                eval file_modified_dates_full_$i=\"\$current_file_modified_date_full\"
                GetFileSizeInBytes current_file_path current_file_path_size_in_bytes
                eval file_size_$i=\"\$current_file_path_size_in_bytes\"
            fi
        done;
    done
    eval archive_paths_0=$i
    
    cd "$initial_dir"
    PrintJustInTitle ""
}

GenerateMatchedFilePaths () {
    #For the variable received as parameter (containing a <find command>) -> print all file paths that match the <search criterias> specified by the user:
    
    for file2 in $(\
        eval "$current_find_command";\
    ); do \
        j=$(($j + 1)); \
        PrintJustInTitle "Step $1: Processing file $j..."; \
        GetFileSizeInBytes file2 file2_size_in_bytes; \
        if [ "$file2_size_in_bytes" -le "$max_archive_size_in_bytes" ]; then \
            not_match="false"; \
            for k in $(GenerateSequence 1 $search_strings_array_0); do \
                eval current_search_string=\"\$search_strings_array_$k\";\
                eval $current_extract_to_screen_command 2>/dev/null|grep -l -i "$current_search_string">/dev/null||{ not_match="true"; break; }; \
            done; \
            if [ "$not_match" = "false" ]; then printf '%s\n' "$file2"; fi; \
        fi; \
    done|sort --numeric-sort
}

PrintMatchedFilesInfo () {
    #For each file in the <ARCHIVE PATHS> array: print the file's: PATH, MODIFIED DATE SECONDS SINCE EPOCH, MODIFIED DATE (LOCAL TIME), SIZE IN BYTES -> for use with 'zenity':
    
    printf '%s\n\n' ">>>">"$print_to_screen"
    sleep 1
    
    for i in $(GenerateSequence 1 $archive_paths_0); do
        PrintJustInTitle "Loading files data: file $i..."
        eval current_file_path=\"\$archive_paths_$i\"
        eval current_file_modified_date_SSE=\"\$file_modified_dates_SSE_$i\"
        eval current_file_modified_date_full=\"\$file_modified_dates_full_$i\"
        eval current_file_size=\"\$file_size_$i\"
        printf "%s \n" "$i"
        printf "%s \n" "$(printf '%05d' "$i")"
        printf "%s \n" "$current_file_path"
        printf "%s \n" "$current_file_modified_date_SSE"
        printf "%s \n" "$current_file_modified_date_full"
        printf "%s \n" "$(printf '%015d%s' "$current_file_size" "B")"
    done
}

CheckUtilities () {
    #Check if any of the necessary utilities (received as string parameters by this function) is missing:
    
    error="false"
    
    for utility; do
        which $utility>/dev/null 2>/dev/null || PrintErrorMessageAndSetError "ERROR: the '$utility' utility is not installed!"
    done
}

PrintInTitle () {
    #Changes the terminal emulator window title to: $1:
    
    printf "\033]0;%s\007" "$1"
}

PrintJustInTitle () {
    #Changes the terminal emulator window title to: $1 (survives output redirection):
    
    PrintInTitle "$1">"$print_to_screen"
}

PressEnterToExit () {
    #Waits for the user to press Enter in order to exit:
    
    printf '%s\n' "Press Enter to exit..."
    read temp
}

GenerateSequence () {
    #Prints the sequence of numbers $1 .. $2 <-> if $1 value < $2 value:
    
    sequence_start=$(($1))
    sequence_end=$(($2))
    if [ "$sequence_start" -le "$sequence_end" ]; then
        seq $sequence_start $sequence_end
    fi
}


print_to_screen='/dev/tty' #Print text to screen only

{

set +f #Enable globbing (POSIX compliant)
setopt no_nomatch 2>/dev/null #Enable globbing (zsh)

Q="'"
max_archive_size_in_bytes=100000000 #approx. 100 MB
initial_dir="$PWD"
StoreIFS initial_IFS

GetOSType OS_TYPE

#Store New Line for use with sed:
if [ "$OS_TYPE" = "Linux" ]; then
    NL2=$(printf '%s' "\n\n")
fi

CheckUtilities stat mkdir rmdir unzip cat grep seq find sed file rm uniq sort

#Trap "INTERRUPT" (CTRL + C) and "TERMINAL STOP" (CTRL + Z) signals:
trap 'trap1' INT
trap 'trap1' TSTP

{
    [ "$OS_TYPE" = "Linux" ] || [ "$OS_TYPE" = "Other" ] && {
        which gedit 2>/dev/null && {
            editor_open_in_same_window_and_wait="gedit -w"
            editor_open_in_new_window_and_wait="gedit --new-window -w"
            editor_open_new_blank_window_and_wait="$editor_open_in_new_window_and_wait"
        } || {
            which kate 2>/dev/null && {
                editor_open_in_same_window_and_wait="kate -w"
                editor_open_in_new_window_and_wait="kate -n -w"
                editor_open_new_blank_window_and_wait="$editor_open_in_new_window_and_wait"
            } || {
                PrintErrorMessageAndSetError "ERROR: Text editor not found (gedit / kate)!"
                PressEnterToExit
            }>&2
        }
    } || {
        PrintErrorMessageAndSetError "ERROR: Unsupported OS!"
        sleep 1
    }>&2
}>/dev/null

if [ "$error" = "true" ]; then
    #printf "\n"
    CleanUp
    exit 1
fi

eval find /dev/null $find_search_archive_total_path_filter>/dev/null || {
    PrintErrorMessage "ERROR: Invalid find parameters provided!"
    CleanUp
    exit 1
}>&2

initial_dir="$PWD"


if [ "$OS_TYPE" = "Linux" ] || [ "$OS_TYPE" = "Other" ]; then
    if [ -e '/dev/shm' ]; then
        TEMPORARY_EXTRACT_PATH='/dev/shm'
    elif [ -e "$HOME" ]; then
        TEMPORARY_EXTRACT_PATH="$HOME"
    else
        PrintErrorMessage "Please provide TEMPORARY_EXTRACT_PATH: "
        read TEMPORARY_EXTRACT_PATH
    fi
fi

TEMPORARY_EXTRACT_FOLDER='TEMP_EXTR_FOLDER' # HARDCODED STRING (SHOULD NOT BE CHANGED)


output_dir=""
error="false"
{
    cd "$TEMPORARY_EXTRACT_PATH" && {
        output_dir="$PWD"
        if [ ! -e "TEMP_EXTR_FOLDER" ]; then
            printf '%s\n' "The specified temporary directory: \"TEMP_EXTR_FOLDER\" - does not exist in the specified location: \"$TEMPORARY_EXTRACT_PATH\" - do you want to create it? [ Yes / No ] (default=Enter=No): "
            read answer
            if [ "$answer" = "Yes" ] || [ "$answer" = "yes" ] || [ "$answer" = "Y" ] || [ "$answer" = "y" ]; then
                mkdir "TEMP_EXTR_FOLDER" || error="true"
            fi
        fi
        cd "TEMP_EXTR_FOLDER" || {
            error="true"
        }
    } || error="true"
} 2>/dev/null
if [ "$error" = "true" ]; then
    PrintErrorMessage "Error: Could not access temporary folder \"TEMP_EXTR_FOLDER\" in the extract location: \"$TEMPORARY_EXTRACT_PATH\"!"
    PressEnterToExit
    exit 1
fi>&2

cd "$initial_dir"
printf "\n"
printf '%s\n' "Current_path = \"$initial_dir\"";
printf "\n"
printf '%s\n' "Where to search path (unquoted (raw)) (default=Enter=.): "
printf '%s' ">> where to search path: >> "
read -r search_path; [ -z "$search_path" ] && search_path="."
if [ ! -e "$search_path" ]; then
    PrintErrorMessage "ERROR: The provided search path: \"$search_path\" does not exist!"
    PressEnterToExit
    exit 1
fi>&2
if [ -d "$search_path" ]; then
    cd "$search_path" || {
        PrintErrorMessage "ERROR: Could not access search dir: \"$search_path\"!"
        PressEnterToExit
        exit 1
    }>&2
    cd "$initial_dir"
fi

printf '\n%s\n' "In-archive file path filter(s): (what file path to lookup in the archive) (default=Enter=\"*\"):">"$print_to_screen"
current_in_archive_file_path_filter="not_defined"
i=0;
while [ -n "$current_in_archive_file_path_filter" ]; do
    printf '%s' ">> add in-archive path filter (concatenated with logical OR): >> "
    IFS= read -r current_in_archive_file_path_filter
    RestoreIFS initial_IFS
    if [ -n "$current_in_archive_file_path_filter" ]; then
        i=$(($i + 1))
        eval in_archive_file_path_filters_$i=\"\$current_in_archive_file_path_filter\"
        total_in_archive_file_path_filters="$total_in_archive_file_path_filters $current_in_archive_file_path_filter"
    fi
done
if [ "$i" = "0" ]; then
    i=$(($i + 1))
    in_archive_file_path_filters_1='"*"'
fi
in_archive_file_path_filters_0=$i

printf '\n%s\n' "Search string:";
current_search_string="not_defined"
search_strings_array_0=0
i=0
while [ -n "$current_search_string" ]; do
    printf '%s' ">> add search string (RegEx) (concatenated with logical AND): >> "
    IFS= read -r current_search_string
    RestoreIFS initial_IFS
    if [ -n "$current_search_string" ]; then
        i=$(($i + 1))
        eval search_strings_array_$i=\"\$current_search_string\"
    fi
done
if [ ! "$i" = "0" ]; then
    eval search_strings_array_0=$i
else
    search_strings_array_1=""
    search_strings_array_0=1
fi

printf '\n%s' "Also open files that match the file path filters but don't match the search string(s) (open them as a secondary group of files (in the same editor window))? [ Yes / No ] (default=Enter=No): "
read answer
if [ "$answer" = "Yes" ] || [ "$answer" = "yes" ] || [ "$answer" = "Y" ] || [ "$answer" = "y" ]; then
    open_non_match_string_files="true"
else
    open_non_match_string_files="false"
fi

IFS='
'

cd "$initial_dir"

printf "\n"

GenerateMatchedFilesArrays
pmfi_result="defined"
count=0
while [ -n "$pmfi_result" ]; do
    PrintJustInTitle "Loading files data..."
    
    count=$(($count + 1))
    
    pmfi_result=$(zenity --list --separator='|' --multiple --width "1900" --height "900" --hide-column='1' --print-column='1' --column "Hidden column" --column "File Path number" --column "File Path" --column "Modified Date number" --column "Modified Date" --column "File Size" $(PrintJustInTitle "Loading files data..."; PrintMatchedFilesInfo; PrintJustInTitle "Please select archives to preview..."))
    
    sequence="$pmfi_result"
    t=0
    temp=""
    while [ ! "$temp" = "$sequence" ]; do
        temp="$sequence"
        current_number="${temp%%"|"*}"
        t=$(($t + 1))
        eval numbers_$t=$(($current_number))
        sequence="${temp#*$number*"|"}"
    done
    numbers_0=$t
    
    RestoreIFS initial_IFS
    
    j=0
    for i in $(GenerateSequence 1 $numbers_0); do
        
        eval current_number=\"\$numbers_$i\"
        
        padded_number="$(printf '%05d' "$current_number")"
        eval current_archive_path=\"\$archive_paths_$current_number\"
        full_current_archive_path="$current_archive_path"
        
        ExtractFirstAndLastPathComponent current_archive_path fpc_current_archive_path lpc_current_archive_path
        cd "$fpc_current_archive_path"
        fpc_current_archive_path="$PWD"
        
        ExtractFirstAndLastPathComponent fpc_current_archive_path fpc_fpc_current_archive_path lpc_fpc_current_archive_path
        current_archive_name_ext="${lpc_current_archive_path}"
        current_archive_name_ext_plus="${current_archive_name_ext}""_extract"
        full_current_archive_extract_to_path="$output_dir/TEMP_EXTR_FOLDER/$padded_number/$lpc_fpc_current_archive_path/$current_archive_name_ext_plus"
        
        if [ ! -e "$full_current_archive_extract_to_path" ]; then
            cd "$output_dir/TEMP_EXTR_FOLDER"
            mkdir "$padded_number"
            cd "$padded_number"
            mkdir "$lpc_fpc_current_archive_path"
            cd "$lpc_fpc_current_archive_path"
            mkdir "$current_archive_name_ext_plus"
            cd "$current_archive_name_ext_plus"
            
            case "$current_archive_path" in
                *'.zip' )
                    unzip "$full_current_archive_path" -d "$full_current_archive_extract_to_path"
                ;;
                *'.7z' )
                    7z x "$full_current_archive_path" -o"$full_current_archive_extract_to_path/"
                ;;
                *'.rar' )
                    unrar x "$full_current_archive_path" "$full_current_archive_extract_to_path/"
                ;;
                *'.tar.bz2' )
                    tar -xvjf "$full_current_archive_path" -C "$full_current_archive_extract_to_path"
                ;;
                *'.tar.xz' )
                    tar -xvJf "$full_current_archive_path" -C "$full_current_archive_extract_to_path"
                ;;
                *'.tar.gz' | *'.tgz' )
                    tar -xvzf "$full_current_archive_path" -C "$full_current_archive_extract_to_path"
                ;;
                *'.tar' )
                    tar -xvf "$full_current_archive_path" -C "$full_current_archive_extract_to_path"
                ;;
                *'.bz2' | *'.xz' | *'.gz' )
                    cp "$full_current_archive_path" "$full_current_archive_extract_to_path"
                    case "$current_archive_path" in
                        *'.bz2' )
                            bzip2 "$full_current_archive_extract_to_path/""$current_archive_name_ext" -d "$full_current_archive_extract_to_path"
                        ;;
                        *'.xz' )
                            xz "$full_current_archive_extract_to_path/""$current_archive_name_ext" -d "$full_current_archive_extract_to_path"
                        ;;
                        *'.gz' )
                            gzip -d "$full_current_archive_extract_to_path/""$current_archive_name_ext"
                        ;;
                    esac
                ;;
            esac >/dev/null 2>/dev/null
        else
            cd "$full_current_archive_extract_to_path"
        fi
        
        new_group=""
        
        for m in $(GenerateSequence 1 $in_archive_file_path_filters_0); do
            eval current_in_archive_path_filter=\"\$in_archive_file_path_filters_$m\"
            IFS=' '
            for current_group_no in 1 2; do
                IFS='
'
                if [ "$current_group_no" = "2" ] && [ -z "$new_group" ]; then
                    break
                fi
                for current_in_archive_file_path in $(eval find . -type f -path $current_in_archive_path_filter|sort --numeric-sort); do
                    TestIfFileIsText current_in_archive_file_path in_archive_file_is_text
                    if [ "$in_archive_file_is_text" = "true" ]; then
                        matched_group="1"
                        for k in $(GenerateSequence 1 $search_strings_array_0); do
                            eval current_search_string=\"\$search_strings_array_$k\"
                            cat "$full_current_archive_extract_to_path/$current_in_archive_file_path"|grep -l -i "$current_search_string">/dev/null||{ matched_group="2"; break; }
                        done
                        
                        if [ "$matched_group" = "$current_group_no" ] && ( ! ( [ "$open_non_match_string_files" = "false" ] && [ "$current_group_no" = "2" ] ) ); then
                            esc_full_current_extr_file_path="$(printf '%s\n' "$full_current_archive_extract_to_path/$current_in_archive_file_path"|sed "s/'/$Q\"\$Q\"$Q/g")"; new_group="$new_group"" ""'$esc_full_current_extr_file_path'"
                        fi
                    fi
                done
                IFS=' '
            done
            RestoreIFS initial_IFS
        done
        
        if [ -n "$new_group" ]; then
            j=$(($j + 1))
            eval groups_$j=\"\$new_group\"
            eval matched_archive_paths_$j=\"\$current_archive_path\"
        fi
    done
    
    groups_0=$j
    matched_archive_paths_0=$j
    
    RestoreIFS initial_IFS
    first_time="true"
    for i in $(GenerateSequence 1 $groups_0); do
        eval current_group="\"\$groups_$i\""
        if [ "$first_time" = "true" ]; then
            { eval $editor_open_new_blank_window_and_wait & }
            sleep 0.5
            { eval $editor_open_in_same_window_and_wait "$current_group" & }
            first_time="false"
        else
            { eval $editor_open_in_new_window_and_wait "$current_group" & }
        fi
        sleep 0.5
    done
    
    IFS='
'
done
RestoreIFS initial_IFS

PrintJustInTitle "Exiting..."; sleep 1; CleanUp
cd "$initial_dir"

}>"$print_to_screen"

Note: In case of using the konsole terminal emulator - in order to be able to display a customized (personal) terminal emulator window title - it is required one initial additional step:

Konsole -> Settings -> Configure Konsole ... ->
-> Enable option "Show window title on the titlebar"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .