in reply to printing escape characters
Minimally: s/\t/\\t/g;
Something more complete:
my %ws = ( "\x09" => qw( \t ), "\x0A" => qw( \n ), "\x0C" => qw( \f ), "\x0D" => qw( \r ), "\x20" => qw( \s ), ); while (<>) { s/(\s)/$ws{$1}/g; print; print "\n"; # keep it line for line. }
Note that printing "\s" for a space is pretty contrived... "\s" really only makes sense in the context of a regular expression. It isn't a real escape for a space.
Something like this would be more general...
perl -pe 's/(\s)/sprintf"\\x%02x",ord$1/ge;$_.=$/'
Update: Added \f and more general one-liner.
-sauoq "My two cents aren't worth a dime.";
|
|---|