1

I'm trying to replace several symbols with spaces, and I thought tr was the right command. So I tried

cat myfile | tr '_[]()-/' ' '

But I get the error

range-endpoints of ']-/' are in reverse collating sequence order

presumably because I can't have a minus sign in the input characters. Can I accomplish this using tr?

2 Answers2

4

The message apparently comes from GNU tr, and perhaps is due to some issue with locale settings. The info page for tr suggests putting the - last in the set, to avoid confusing it as part of a range, e.g.,

cat myfile | tr '_[]()/-' ' '
Thomas Dickey
  • 76,765
1

With any POSIX tr:

tr '_][()/-' '[ *]' <file

will work.

Note that the use of [ *] is required by POSIX. In:

tr string1 string2

When string2 shorter than string1, a BSD tr will pad string2 with the last character of string2, so tr '_][()/-' ' ' is not guaranteed to work.

cuonglm
  • 153,898