<commit_before>#!/usr/bin/env bash
# ------------------------------------------------------------------
shopt -s extglob

abspath_script="$(readlink -f -e "$0")"
script_absdir="$(dirname "$abspath_script")"
script_name="$(basename "$0" .sh)"

if [ $# -eq 0 ]
    then
        cat "$script_absdir/${script_name}_help.txt"
        exit 1
fi

TEMP=$(getopt -o h -l help -n "$script_name.sh" -- "$@")

if [ $? -ne 0 ]
then
  echo "Terminating..." >&2
  exit -1
fi

eval set -- "$TEMP"

# Defaults

while true
do
  case "$1" in
    -h|--help)			
      cat "$script_absdir/${script_name}_help.txt"
      exit
      ;;
    --)
      shift
      break
      ;;
    *)
      echo "$script_name.sh:Internal error!"
      exit 1
      ;;
  esac
done

# Prefix of the target logfiles
prefix="$1"

# Print colum names
printf "Library\tinitial_reads\tafter_polyAT\tafter_chrM\tafter_rRNA\tfinal_reads\n" > "summary_${prefix}.log"

# Parse logfiles
for f in "${prefix}"*;
do
  # Get library name
  temp="${f%*.log}"
  library="${temp#${prefix}_}"
  # Parse number of initial reads
  initial_reads="$(cat "$f" | sed -n -e 's/Processing total of //p' | sed -n -e 's/ reads//p')"
  printf "${library}\t${initial_reads}"
  # Reads after each filter
  percentages="$(cat "$f" | grep %)"
  while read line; do 
    temp="\t${line::2}"
    printf "${temp}%%"
  done < <(echo "$percentages")
  # Total reads in the end<commit_msg>Script to collapse all logfiles with the same prefix<commit_after>#!/usr/bin/env bash
# ------------------------------------------------------------------
shopt -s extglob

abspath_script="$(readlink -f -e "$0")"
script_absdir="$(dirname "$abspath_script")"
script_name="$(basename "$0" .sh)"

if [ $# -eq 0 ]
    then
        cat "$script_absdir/${script_name}_help.txt"
        exit 1
fi

TEMP=$(getopt -o h -l help -n "$script_name.sh" -- "$@")

if [ $? -ne 0 ]
then
  echo "Terminating..." >&2
  exit -1
fi

eval set -- "$TEMP"

# Defaults

while true
do
  case "$1" in
    -h|--help)			
      cat "$script_absdir/${script_name}_help.txt"
      exit
      ;;
    --)
      shift
      break
      ;;
    *)
      echo "$script_name.sh:Internal error!"
      exit 1
      ;;
  esac
done

# Prefix of the target logfiles
prefix="$1"

# Print colum names
printf "Library\tinitial_reads\tafter_polyAT\tafter_chrM\tafter_rRNA\tfinal_reads\n" > "summary_${prefix}.log"

# Parse logfiles
for f in "${prefix}"*;
do
  # Get library name
  temp="${f%*.log}"
  library="${temp#${prefix}_}"
  # Parse number of initial reads
  initial_reads="$(cat "$f" | sed -n -e 's/Processing total of //p' | sed -n -e 's/ reads//p')"
  printf "${library}\t${initial_reads}"
  # Reads after each filter
  percentages="$(cat "$f" | grep %)"
  while read line; do 
    temp="${line::2}"
    printf "\t${temp}%%"
  done < <(echo "$percentages")
  # Total reads in the end
{'fraction_non_alphanumeric': 0.21661409043112514, 'fraction_numerical': 0.0077111812127585, 'mean_word_length': 2.4097968936678615, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6323177', 'n_tokens_mistral': 1043, 'n_tokens_neox': 1003, 'n_words': 267}