Page 1 of 1

Get rid of strange characters in a file

Posted: Thu 17 Jan 2013, 01:40
by don570
I had a problem with strange characters appearing in a file that
I created.

Image

Here's the script that caused the problem.

Code: Select all

#!/bin/sh

top -n 1 > /tmp/top.tmp
sed -n '/Mem\:/p' /tmp/top.tmp > /tmp/top.tmp2  # find the MEMORY line
LINE=`cat /tmp/top.tmp2 | awk -F, '{ print $1    $2 }'`
echo $LINE >> /tmp/report-video
rm -f /tmp/top.tmp*
I solved it with just one line of additional code.
By the way most of these special characters appear to be two-byte.
Also note that I put a backslash in front of the character
to protect the character.

Code: Select all

#!/bin/sh

top -n 1 > /tmp/top.tmp
sed -n '/Mem\:/p' /tmp/top.tmp > /tmp/top.tmp2
sed -i  's/\//g;s/\[H//g;s/\[J//g'   /tmp/top.tmp2
LINE=`cat /tmp/top.tmp2 | awk -F, '{ print $1    $2 }'`
echo $LINE >> /tmp/report-video
rm -f /tmp/top.tmp*
Final output in my app 'report-video'....

Image


_______________________________________________

Posted: Thu 24 Jan 2013, 01:27
by don570
The 'free' command is a much better way to get the memory
usage of a computer.

___________________________________