Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Script troubles.



John Whitfield <john_whitfield at email.com> writes:
> I've got a file I'm trying to send that has bad
> characters in it (ASCII 142).
> 
> cat infile.dat | sed "s/<<junk>>/<<blank>>/g" > outfile.dat
> 
> The stream editor is easy enough...
I gave up on remembering how to use sed/awk/tr/etc. a long time ago 
and switch to doing everything with Perl. But the solution is pretty 
much the same. The thing to know is that you need to convert decimal 
142 to octal to use the common backslash escape (of course in Perl 
there's 3 or 4 other ways to do this too). So one possible answer is:

perl -i.bak -pe 'tr/\216//d' files...

-i	edit file "in place"
.bak	create a backup file with .bak appended to the name
 -p	print out everything that is read in
e	execute the commands that follow
tr	same as 'tr' shell command
\216	octal for 142
//	empty replacement set
d	delete the characters found in the search set

or duplicating what you have above:

perl -pe 'tr/\216//d' infile.dat > outfile.dat

 -Tom

-- 
Tom Metro
Venture Logic                                     tmetro at vl.com
Newton, MA, USA

-
Subcription/unsubscription/info requests: send e-mail with
"subscribe", "unsubscribe", or "info" on the first line of the
message body to discuss-request at blu.org (Subject line is ignored).




BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org