-3

I've been recently introduced to shell scripting and would like to know the utility to delete all non-ascii characters. And most notably how to replace the ascii characters from (1 -31) with it's control char.

ProxyStudent
  • 101
  • 1
  • 1
  • 8
  • Which Unix and which shell? And what does “replace the ascii characters from (1 -31) with it's control char” mean? – Dour High Arch Apr 17 '16 at 00:50
  • like for example backspace would print out "^H" or cancel would print out "^X" like on this ascii table here http://www.physics.udel.edu/~watson/scen103/ascii.html – ProxyStudent Apr 17 '16 at 01:11

1 Answers1

0

Here is how to go with tr command (translate characters)

If you want to keep only "ascii chars" except those between 128 and 255 in your a.in file with Unix:

cat a.in | tr -cd '\128-\255'

If you wan to remove "ascii chars" that are not between 32 and 255:

cat a.in | tr -d '\0-\31' |tr -d '\255-\377'

Maybe the answer of How do I grep for all non-ASCII characters in UNIX could also be of some help.

Community
  • 1
  • 1
J. Chomel
  • 8,193
  • 15
  • 41
  • 69