strange character after ">>"

I use below bash script to write file

Code:
#!/usr/bin/bash

top -n 1 -s | head -n 4 >> tmp.tmp
line=` cat tmp.tmp|wc -l `
echo $line
while [ $line -gt 0 ]
do
a=`cat tmp.tmp | head -n $line | tail -n 1 `
echo $a
echo $a >> tmp1.tmp
line=`expr $line - 1`
done

I vi the tmp.tmp and tmp1.tmp file and get strange character ...
how I can fix it ....

Code:
^[[H^[[2J^[[m^[(Btop - 17:49:08 up 19 min,  2 users,  load average: 0.09, 0.16, 0.28^[[m^[(B^[[39;49m^[[K
Tasks:^[[m^[(B^[[39;49m^[[m^[(B  74 ^[[m^[(B^[[39;49mtotal,^[[m^[(B^[[39;49m^[[m^[(B   1 ^[[m^[(B^[[39;49mrunning,^[[m^[(B^[[39;49m^[[m^[(B  73 ^[[m^[(B^[[39;49msleeping,^[[m^[(B^[[39;49m^[[m^[(B   0 ^[[m^[(B^[[39;49mstopped,^[[m^[(B^[[39;49m^[[m^[(B   0 ^[[m^[(B^[[39;49mzombie^[[m^[(B^[[39;49m^[[K
Cpu(s):^[[m^[(B^[[39;49m^[[m^[(B  0.6% ^[[m^[(B^[[39;49mus,^[[m^[(B^[[39;49m^[[m^[(B 10.8% ^[[m^[(B^[[39;49msy,^[[m^[(B^[[39;49m^[[m^[(B  0.0% ^[[m^[(B^[[39;49mni,^[[m^[(B^[[39;49m^[[m^[(B 81.1% ^[[m^[(B^[[39;49mid,^[[m^[(B^[[39;49m^[[m^[(B  7.3% ^[[m^[(B^[[39;49mwa,^[[m^[(B^[[39;49m^[[m^[(B  0.2% ^[[m^[(B^[[39;49mhi,^[[m^[(B^[[39;49m^[[m^[(B  0.0% ^[[m^[(B^[[39;49msi^[[m^[(B^[[39;49m^[[K
Mem: ^[[m^[(B^[[39;49m^[[m^[(B  2567708k ^[[m^[(B^[[39;49mtotal,^[[m^[(B^[[39;49m^[[m^[(B   391228k ^[[m^[(B^[[39;49mused,^[[m^[(B^[[39;49m^[[m^[(B  2176480k ^[[m^[(B^[[39;49mfree,^[[m^[(B^[[39;49m^[[m^[(B    44964k ^[[m^[(B^[[39;49mbuffers^[[m^[(B^[[39;49m^[[K
~
~
~
~
~
~
~
~
"tmp.tmp" 4L, 912C
 
a) don't use bash for this
b) it's top that's causing it
 
Code:
#!/usr/bin/bash

That's a new one ..

AFAICS, the script would work on FreeBSD with bash or sh. No idea why that -s is in the top command. And no idea what OS you're using.
 
Back
Top