Get rid of strange characters in a file

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

Get rid of strange characters in a file

#1 Post 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


_______________________________________________

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#2 Post by don570 »

The 'free' command is a much better way to get the memory
usage of a computer.

___________________________________

Post Reply