ResultDiff: Difference between revisions

From Essential
Jump to navigation Jump to search
(Undo revision 1601 by Tcepo (talk))
Tag: Undo
Line 18: Line 18:


# initialisation des variables
# initialisation des variables
baseDir="$(realpath . )"
baseDir="$(realpath "$(dirname $0)"/..)"
cacheFile=/tmp/"$(basename $0)"$$
cacheFile=/tmp/"$(basename $0)"$$



Revision as of 14:01, 4 August 2023

AUTOMATED

  • Set variables :
export resultDiff=~/resultDiff
  • Execute :
mkdir -p ~/old &&\
curl https://infocepo.com/wiki/index.php/Special:Export/ResultDiff 2>/dev/null |tac |sed -r '0,/'"#"'24cc42#/d' |tac |sed -r '0,/'"#"'24cc42#/d' |sed 's/'"&"'amp;/\&/g;s/'"&"'gt;/>/g;s/'"&"'lt;/</g' >~/old/$$ &&\
bash ~/old/$$

code

#24cc42#
#https://github.com/ynotopec/diff-multi

#[ $# -lt 1 ] &&exit

# initialisation des variables
baseDir="$(realpath "$(dirname $0)"/..)"
cacheFile=/tmp/"$(basename $0)"$$

########### commun algo
rm -rf /tmp/analyse*
#filesList="$(ls -1d $1/*)"
[ -z "${resultDiff}" ] &&resultDiff="${OLDPWD}"
filesList="$(ls -1d ${resultDiff}/*)"

# work dirs
mkdir -p /tmp/analyse$$/files /tmp/analyse$$/diff

# cp files and unzip
echo "${filesList}" |while read fileName ;do
  cp -p "${fileName}" /tmp/analyse$$/files/.
done
gunzip /tmp/analyse$$/files/*.gz 2>/dev/null
filesList="$(ls -1d /tmp/analyse$$/files/*)"

## find words
# stat words
echo "${filesList}" |while read fileName ;do
  cat "${fileName}" \
    |tr -c "[:alnum:]_" "[\n*]" |grep -v "^\s*$" |sort -u
done \
  >/tmp/analyse$$/statWords

triggerValue=$(($(ls -1d /tmp/analyse$$/files/* |wc -l) / 2))

# keep vars words
#awk 'NR == FNR {count[$0]++; next}; count[$0] <= '"${triggerValue}" /tmp/analyse$$/statWords /tmp/analyse$$/statWords |sort -u >/tmp/analyse$$/statWords.vars

# replace vars
cp -a /tmp/analyse$$/files /tmp/analyse$$/files.cache
cat /tmp/analyse$$/statWords.vars |while read lineMy ;do sed -i "s#\b${lineMy}\b#\${varMy}#g" /tmp/analyse$$/files.cache/* ;done 2>/dev/null

# comm = /tmp/analyse$$/comm
ls -1d /tmp/analyse$$/files.cache/* |while read fileName ;do
  cat "${fileName}" \
    |awk '!seen[$0]++'
done \
  >/tmp/analyse$$/comm

awk 'NR == FNR {count[$0]++; next}; count[$0] > '"${triggerValue}" /tmp/analyse$$/comm /tmp/analyse$$/comm \
  |awk '!seen[$0]++' >/tmp/analyse$$/comm2
mv -f /tmp/analyse$$/comm2 /tmp/analyse$$/comm

# diff = /tmp/analyse$$/diff/
ls -1d /tmp/analyse$$/files.cache/* |while read fileName ;do
  ( echo "== $(basename "${fileName}") =="
    cat "${fileName}"
    echo "=== missing ==="
    cat /tmp/analyse$$/comm
  ) >/tmp/analyse$$/tmp

  awk 'NR == FNR {count[$0]++; next}; count[$0] == 1' /tmp/analyse$$/tmp /tmp/analyse$$/tmp \
    |tee /tmp/analyse$$/diff/"$(basename "${fileName}")"
done

# libère cache
rm -f /tmp/"$(basename $0)"$$*
#24cc42#

Summary from ChatGPT

This is a shell script written in Bash. The script starts by setting the "resultDiff" variable to a specific file path. The script then performs the following actions:

  1. Creates a directory called "old" in the home directory.
  2. Changes the current working directory to the "old" directory.
  3. Downloads a file from "https://infocepo.com/wiki/index.php/Special:Export/ResultDiff", filters the data, and saves it to a temporary file.
  4. Runs the temporary file.
  5. Returns to the previous working directory.

The second part of the code is a more complex shell script that performs multiple actions related to file analysis and comparison. The script does the following:

  1. Cleans up previous temporary files.
  2. Makes two directories, "analyse$$/files" and "analyse$$/diff".
  3. Copies all files from the "resultDiff" directory to the "analyse$$/files" directory, and unzips any ".gz" files.
  4. Generates a list of unique words from all the files in the "analyse$$/files" directory.
  5. Triggers an action if the number of files is above a certain value.
  6. Replaces the words in the list with a placeholder, "varMy".
  7. Compares the contents of all files in the "analyse$$/files" directory and creates a new file, "analyse$$/comm", with all common lines.
  8. Filters out the lines in "analyse$$/comm" that are not present in more than half of the files.
  9. Generates a "diff" file for each file in the "analyse$$/files" directory, showing the contents of the file and the missing common lines.
  10. Cleans up temporary files.