#!/bin/bash for file in *.ttyrec; do if ttygrep 'ascend to the status of Demi' $file | grep -q ttyrec; then mv $file $(echo $file | sed 's/\(.*\)\.\(ttyrec\)/\1a.\2/') fi done