Skip/remove non-ascii character with sed

前端 未结 6 1019
孤街浪徒
孤街浪徒 2020-12-07 01:19

Chip,Dirkland,DrobæSphere Inc,cdirkland@hotmail.com,usa

I\'ve been trying to use sed to modify email addresses in a .csv but the line ab

6条回答
  •  -上瘾入骨i
    2020-12-07 01:40

    This might work for you (GNU sed):

    echo "Chip,Dirkland,DrobæSphere Inc,cdirkland@hotmail.com,usa" |
    sed 's/\o346/a+e/g'
    Chip,Dirkland,Droba+eSphere Inc,cdirkland@hotmail.com,usa
    

    Then do what you have to do and after to revert do:

    echo "Chip,Dirkland,Droba+eSphere Inc,cdirkland@hotmail.com,usa" | 
    sed 's/a+e/\o346/g'
    Chip,Dirkland,DrobæSphere Inc,cdirkland@hotmail.com,usa
    

    If you have tricky characters in strings and want to understand how sed sees them use the l0 command (see here). Also very useful for debugging difficult regexps.

    echo "Chip,Dirkland,DrobæSphere Inc,cdirkland@hotmail.com,usa" | 
    sed -n 'l0'
    Chip,Dirkland,Drob\346Sphere Inc,cdirkland@hotmail.com,usa$
    

提交回复
热议问题