Created
April 11, 2012 00:26
-
-
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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