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

While working on sed command stricken with this, error : “sed: -e expression #1, char 24: Invalid range end “). To solve this problem, we have used sed and tr command.

We made a bash script having expect command in it. We were passing variable value from my mysql database into the bash script.

The output which was coming from mysql was appearing like this —
sed expression error

The problem was coming because the sed command which we used was giving right output i.e 351 only in terminal.
But in my bash script variable it seems it was also taking some other unknown characters or spaces.

Here the plus(+) sign is a special character.

The solution come when we used the below tr command in our bash script. It has trimmed the special character from the output which we got from mysql command.

ID=`mysql -uUsername -pPASSWORDXXX -e "select id from databasename.tablename where name = ''linuxtribe"| sed -e 's/[!@#$%^&*()]//g'|sed '1d'|tr -cds "[:alnum:]" "[ ]"`

The troubleshooting which we did ,is not same with every such error.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.