If you only want to isolate the cpu usage stat, couldn't you just use awk the grab the fields you want?
Code:
top -n 1 -u $USER | grep $USER | awk '{ OFS="\t"; print $2,$3,$10 }' -
Otherwise, I think it's the color escape characters that you're seeing (maybe a sample of your output would help identify it), and I found this sed command before to help get rid of those characters:
Code:
top -n 1 -u $USER | grep $USER | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"
Does that help?
EDIT: Actually might be able to get away with simplifying that a bit:
Code:
top -n 1 -u $USER | grep $USER | sed -r "s:\x1B\[[0-9;]*[mK]::g"
Bookmarks