<commit_before>#!/bin/bash
set -o nounset

if [[ $# -lt 2 ]]; then
    echo "usage: $0 marc_grep_conditional_expression filename1 [filename2 ... filenameN]"
    exit 1
fi
marc_grep_conditional_expression="$1"
shift

found=1
for filename in "$@"; do
    if [[ ! $filename =~ \.tar\.gz$ ]]; then
	marc_grep_output=$(marc_grep "$filename" "$marc_grep_conditional_expression" 3>&2 2>&1 1>&3)
        if [[ $? -ne 0 ]]; then
            echo "marc_grep failed ($marc_grep_output)!"
            exit 1
        fi
        last_line=$(echo "$marc_grep_output" | tail -1)
        if [[ ! $last_line =~ ^Matched\ 0 && $last_line =~ ^Matched ]]; then
	    echo "was found in $filename"
            found=0
	fi
    else
	tar_filename=${filename%.gz}
	gunzip < "$filename" > "$tar_filename"
	for archive_member in $(tar --list --file "$tar_filename"); do
	    tar --extract --file "$tar_filename" "$archive_member"
	    marc_grep_output=$(marc_grep --input-format=marc-21 "$archive_member" "$marc_grep_conditional_expression" 3>&2 2>&1 1>&3)
            if [[ $? -ne 0 ]]; then
                echo "marc_grep failed ($marc_grep_output)!"
                exit 1
            fi
            last_line=$(echo "$marc_grep_output" | tail -1)<commit_msg>remove temp. files in failed branch<commit_after>#!/bin/bash
set -o nounset

if [[ $# -lt 2 ]]; then
    echo "usage: $0 marc_grep_conditional_expression filename1 [filename2 ... filenameN]"
    exit 1
fi
marc_grep_conditional_expression="$1"
shift

found=1
for filename in "$@"; do
    if [[ ! $filename =~ \.tar\.gz$ ]]; then
	marc_grep_output=$(marc_grep "$filename" "$marc_grep_conditional_expression" 3>&2 2>&1 1>&3)
        if [[ $? -ne 0 ]]; then
            echo "marc_grep failed ($marc_grep_output)!"
            exit 1
        fi
        last_line=$(echo "$marc_grep_output" | tail -1)
        if [[ ! $last_line =~ ^Matched\ 0 && $last_line =~ ^Matched ]]; then
	    echo "was found in $filename"
            found=0
	fi
    else
	tar_filename=${filename%.gz}
	gunzip < "$filename" > "$tar_filename"
	for archive_member in $(tar --list --file "$tar_filename"); do
	    tar --extract --file "$tar_filename" "$archive_member"
	    marc_grep_output=$(marc_grep --input-format=marc-21 "$archive_member" "$marc_grep_conditional_expression" 3>&2 2>&1 1>&3)
            if [[ $? -ne 0 ]]; then
                echo "marc_grep failed ($marc_grep_output)!"
                rm "$archive_member"
                rm "$tar_filename"
                exit 1
            fi
            last_line=$(echo "$marc_grep_output" | tail -1)
{'fraction_non_alphanumeric': 0.14937597503900157, 'fraction_numerical': 0.02262090483619345, 'mean_word_length': 2.6382978723404253, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3501571', 'n_tokens_mistral': 937, 'n_tokens_neox': 877, 'n_words': 216}