Last active
November 20, 2020 03:00
-
-
Save sylwit/a34b45cf3eea84e15083925b32db5351 to your computer and use it in GitHub Desktop.
asciinema rewrite
This file contains 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 | |
# This script rewrites history of an asciinema cast from a starting point in time | |
# ex: ./asciinema_rewrite.sh in.cast 17.452 3 > out.cast, will remove 3 seconds of each record after 17.452sec | |
if [[ $# -ne 3 ]]; then | |
echo "Invalid number of arguments" | |
echo "Usage: $0 filename starting_time remove_time > out.cast" | |
exit 2 | |
fi | |
FILE=$1 | |
START=$2 | |
REMOVE=$3 | |
while IFS= read -r line | |
do | |
if [[ $line =~ ^\[([0-9.]*) ]]; then | |
TIME=${BASH_REMATCH[1]} | |
if (( $(echo "$TIME >= $START" | bc -l) )); then | |
NEWTIME=$(echo "scale=6;${TIME}-${REMOVE}" | bc -l) | |
echo "${line/${TIME}/${NEWTIME}}" | |
else | |
echo "$line" | |
fi | |
else | |
echo "$line" | |
fi | |
done < "$FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment