#!/bin/bash while read line do echo "${line}" | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2};?)?)?[mGK]//g" | sed 's/ *$/ /' done