Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 20 Oct 2014, 06:18
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Get rid of strange characters in a file
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [2 Posts]  
Author Message
don570


Joined: 10 Mar 2010
Posts: 3331
Location: Ontario

PostPosted: Wed 16 Jan 2013, 21:40    Post subject:  Get rid of strange characters in a file  

I had a problem with strange characters appearing in a file that
I created.



Here's the script that caused the problem.

Code:
#!/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:

#!/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'....




_______________________________________________
Back to top
View user's profile Send private message 
don570


Joined: 10 Mar 2010
Posts: 3331
Location: Ontario

PostPosted: Wed 23 Jan 2013, 21:27    Post subject:  

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

___________________________________
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [2 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0437s ][ Queries: 11 (0.0044s) ][ GZIP on ]