top
uses ANSI escape codes to highlight memory values, which your terminal is able to interpret but your text editor isn't. For your need, you're probably better off reading /proc/meminfo
directly, like this:
cat /proc/meminfo|grep MemTotal|awk '{print $2}' >> tst1