[olug] Unix Tip: REMOVING CONTROL CHARACTERS

Jay Hannah jay at jays.net
Tue Apr 1 23:46:55 UTC 2003



On Tue, 1 Apr 2003, Unix Guru Universe wrote:
> REMOVING CONTROL CHARACTERS
>
> Have you ever faced problem of removing
> Control Characters from Multiple Files,
>
> Here is the solution create script file
> with following entries,
>
> vi -c "%s/^M//g" -c "wq" junk1.c
> vi -c "%s/^M//g" -c "wq" junk2.c
> vi -c "%s/^M//g" -c "wq" junk3.c
> vi -c "%s/^M//g" -c "wq" junk4.c
> vi -c "%s/^M//g" -c "wq" junk5.c
> vi -c "%s/^M//g" -c "wq" junk6.c


Perl Mongers would:

   perl -pi -e 's/\cM//g' junk*.c

Or better yet, remove all characters not in ASCII " " through "~":

   perl -pi -e 's/[^ -~]//g' junk*.c


Cheers,

Jay Hannah
Omaha Perl Mongers: http://omaha.pm.org







More information about the OLUG mailing list