in reply to Searching for control characters
Run it like this:#!/usr/bin/perl use strict; use warnings; while (<>) { my @ctrl = ( /([[:ctrl:]])/g ); if ( @ctrl ) { my $cstr = join ",", map { sprintf "x%2.2x",ord() } @ctrl; s/([[:ctrl:]])/sprintf("||%x2.2x||",$1)/eg; printf( "line %d: ctrl-chars %s in <<%s>>\n", $., $cstr, $_ ); } }
It'll behave a little differently from your version: if a single line contains two or more control characters, this will show all of them (e.g. "x13,x01,x11"), instead of showing just the first one.script_name memo.txt > memo.errs
That could also be done as a one-liner (using "perl -lne"), but then you might have shell quoting issues that I don't want to get into...
(UPDATE: Added a line of code inside the "if(@ctrl)" block, to mark the locations in the data line where the control characters occurred, as per OP's stated intention.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Searching for control characters
by ericdp (Novice) on Feb 08, 2006 at 16:45 UTC | |
by ericdp (Novice) on Feb 08, 2006 at 17:31 UTC |