Behaviour of character ranges depend on the locale, that is the internationalisation settings. Different locales have different order for characters. For instance in a French locale (and most locales where there is a â character), â will be after a and before b.
The C locale is one that is not language specific (or US English specific when it has to make a choice), in that locale, characters are bytes and they sort by their byte value.
The locales area that tr is concerned about are LC_CTYPE to define the type of character, and LC_COLLATE to define the order of characters. Note that nowadays the characters have variable number of bytes as utf-8 is becoming more and more common as the default character set.
Those can be specified using environment variables of the same name. LC_ALL however overrides them all. So to be sure to get the behavior you want, you have to either unset LC_ALL and set the ones you like or simpler, just set LC_ALL:
LC_ALL=C tr -cd '\0-\177'
Or:
LC_ALL=C tr -d '\200-\377'
That also works for utf-8 data because utf-8 is a superset of ASCII and all the non-ASCII characters have the eighth bit set in all their bytes.
strings <non-ASCII_file.dat >ASCII_file.txt– Johan Mar 19 at 10:27LC_ALL=C /usr/xpg4/bin/tr -cd '\0-\177'? – Stephane Chazelas Mar 19 at 11:12tr? And could you please elaborate this in the answer section? – Sri M. Mar 19 at 12:33