skip to Main Content
#!/bin/sh
emoji="U1f300-U1f5ffU1f900-U1f9ffU1f600-U1f64fU1f680-U1f6ffU2600-U26ffU2700-U27bfU1f1e6-U1f1ffU1f191-U1f251U1f004U1f0cfU1f170-U1f171U1f17e-U1f17fU1f18eU3030U2b50U2b55U2934-U2935U2b05-U2b07U2b1b-U2b1cU3297U3299U303dU00a9U00aeU2122U23f3U24c2U23e9-U23efU25b6U23f8-U23fa"
sample="This ๐Ÿ’ is โญ a ๐Ÿข line ๐Ÿคฎ of ๐Ÿ˜ƒ emoji โœˆ"
echo $sample
echo $sample | LC_ALL=UTF-8 sed -e "s/[$(printf $emoji)]//g"

The preceding script can obtain normal execution results on other Linux operating systems (such as centos). However, if the script is executed on OpenWRT, an error message is displayed sed: bad regex Invalid character range or the correct result cannot be obtained after execution. Attempts were made to change the sed version to 4.8 but the problem persisted. Is this bash or is the system environment incomplete?

  1. Attempts were made to change the sed version to 4.8 but the problem persisted
  2. emoji="U1f300-U1f5ff" Trying to shorten emoji also works on centos, not openwrt

2

Answers


  1. Chosen as BEST ANSWER

    If it is a system shell environment problem, but the following script can get normal results

    grep -Pv '[x{1f300}-x{1f5ff}x{1f900}-x{1f9ff}x{1f600}-x{1f64f}x{1f680}-x{1f6ff}x{2600}-x{26ff}x{2700}-x{27bf}x{1f1e6}-x{1f1ff}x{1f191}-x{1f251}x{1f004}x{1f0cf}x{1f170}-x{1f171}x{1f17e}-x{1f17f}x{1f18e}x{3030}x{2b50}x{2b55}x{2934}-x{2935}x{2b05}-x{2b07}x{2b1b}-x{2b1c}x{3297}x{3299}x{303d}x{00a9}x{00ae}x{2122}x{23f3}x{24c2}x{23e9}-x{23ef}x{25b6}x{23f8}-x{23fa}]'
    

  2. May not be the answer but your quoting’s wrong, shebang is wrong, use of printf is wrong, use of echo instead of printf is wrong, locale is wrong, and you have a useless subshell calling printf so let’s clean up all of that and then see if you still have a problem. Try this:

    $ cat tst.sh
    #!/usr/bin/env bash
    
    emoji='U1f300-U1f5ffU1f900-U1f9ffU1f600-U1f64fU1f680-U1f6ffU2600-U26ffU2700-U27bfU1f1e6-U1f1ffU1f191-U1f251U1f004U1f0cfU1f170-U1f171U1f17e-U1f17fU1f18eU3030U2b50U2b55U2934-U2935U2b05-U2b07U2b1b-U2b1cU3297U3299U303dU00a9U00aeU2122U23f3U24c2U23e9-U23efU25b6U23f8-U23fa'
    sample='This ๐Ÿ’ is โญ a ๐Ÿข line ๐Ÿคฎ of ๐Ÿ˜ƒ emoji โœˆ'
    printf '%sn' "$sample"
    printf '%sn' "$sample" | LC_ALL=en_GB.UTF-8 sed -e $'s/[$emoji]//g'
    

    $ ./tst.sh
    This ๐Ÿ’ is โญ a ๐Ÿข line ๐Ÿคฎ of ๐Ÿ˜ƒ emoji โœˆ
    Ths ๐Ÿ’ s โญ a ๐Ÿข ln ๐Ÿคฎ f ๐Ÿ˜ƒ  โœˆ
    

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search