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 Tue 25 Nov 2014, 20:44
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 Posts_count  
Author Message
don570


Joined: 10 Mar 2010
Posts: 3379
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: 3379
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:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0453s ][ Queries: 12 (0.0045s) ][ GZIP on ]