Script troubles.

Tom Metro tm at vl.com
Fri Apr 6 11:39:36 EDT 2001


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).



More information about the Discuss mailing list