Skip to content

Instantly share code, notes, and snippets.

@DarkStorm652
Created April 11, 2012 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DarkStorm652/2355918 to your computer and use it in GitHub Desktop.
Save DarkStorm652/2355918 to your computer and use it in GitHub Desktop.
Merges xchat logs (or any other logs of textual form). Run as: ./merge_logs.sh <source directory> <output directory>
#!/bin/bash
directory=$1
output_dir=$2
start=$(date +%s)
start_millis=$(date +%s.%N)
if [ ! -d "$directory" ];then
echo "Source directory is not a directory or does not exist!"
exit
fi
if [ ! -e "$output_dir" ];then
mkdir "$output_dir"
elif [ ! -d "$output_dir" ];then
echo "Output directory is exists and is not a directory!"
fi
echo "Processing..."
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for sub_dir in $(find "$directory" -type f -exec ls {} \;);do
grep -v -e "^\*\*\*\* BEGIN LOGGING AT" -e "^\*\*\*\* ENDING LOGGING AT" "$sub_dir" >> "$output_dir/$(basename "$sub_dir")"
done
IFS=$SAVEIFS
end=$(date +%s)
end_millis=$(date +%s.%N)
diff=$(( $end - $start ))
diff_millis_untrimmed=$(echo "$end_millis - $start_millis" | bc)
diff_millis=${diff_millis_untrimmed:0:4}
echo "Done in "$diff"s ("$diff_millis"ms)."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment