I'm developing a bash script file that will log all CPU data, but when I log that data to log file I'm getting some irregular symbol entries in that log file.
echo "Hi" $(top -n 1 | grep 'Mem' | cut -d ':' -f2 | cut -d ',' -f1 | cut -d 't' -f1) >> tst1
This command will print total available memory. Now in the terminal I'm getting proper values, also in cat
I'm getting proper values, but when I open this log file in gedit, at that time I'm getting some unknown symbol entries like:
(B[m[39;49m(B[m 3918912k (B[m[39;49m
Now I don't know how this unknown guests get into my log file.
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