Search code examples
linuxsed

sed: Invalid range end


I am using Lubuntu 19.04. I have a file called text which contains a mixture of upper case and lowercase characters. I am trying to replace all of these characters with '*', but I'm being given an error message.

sed: -e expression #1, char 11: Invalid range end

This is my code : sed 's/[A-z]/*/g' text

I was expecting an output of stars (*) to be shown on the screen, but instead I get this error message: sed: -e expression #1, char 11: Invalid range end

How do I fix this?


Solution

  • You get an error since you have a invalide range [A-z] with mix of upper/lower case

    Correct range should be [a-z] all lower case, or [A-Z] all upper cas, or [a-zA-Z] mix, same as [a-Z]

    So to replace all letter (upper and lower) with * you should use:

    sed 's/[a-zA-Z]/*/g' text
    sed 's/[A-Za-z]/*/g' text
    sed 's/[a-Z]/*/g' text