Find the answer to your Linux question:
Results 1 to 7 of 7
Hi forum, i have a small sed script witch strips all special chars from stdin sed -e "s/[^Aa0-Zz9]/_/g" My enviroment var LANG is pt_PT.UTF-8 and when i try to strip ...
  1. #1
    Just Joined!
    Join Date
    Jul 2007
    Posts
    4

    sed strict pattern

    Hi forum,

    i have a small sed script witch strips all special chars from stdin
    sed -e "s/[^Aa0-Zz9]/_/g"

    My enviroment var LANG is pt_PT.UTF-8 and when i try to strip something like this

    echo "Página de teste" | sed -e "s/[^Aa0-Zz9]/_/g"

    it outputs 'Página_de_teste' instead of 'P_gina_de_teste' or even better 'Pagina_de_teste'

    some help please...

  2. #2
    Linux User
    Join Date
    Jun 2007
    Posts
    318
    Did you '# export LANG' after setting it?

  3. #3
    Just Joined!
    Join Date
    Jul 2007
    Posts
    4
    Thats my native lang, i've installed the box (CentOS 4.5) with this lang, and i want to keep it.

    The thing is sed thinks that 'á' is included in my search pattern and that's not good.
    I just want sed to distinguish one from another.

  4. #4
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Try:

    Code:
    echo "Página de teste" | sed 's/[^A-Z ^a-z ^0-9]/_/g'
    Regards

  5. #5
    Just Joined!
    Join Date
    Jul 2007
    Posts
    4
    Quote Originally Posted by Franklin52 View Post
    Try:

    Code:
    echo "Página de teste" | sed 's/[^A-Z ^a-z ^0-9]/_/g'
    Regards
    Thanks, but still not working, the output is
    'Página de teste'

  6. #6
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    You can try something like:

    Code:
    echo "Página de teste" | sed 's/[^A-Z^a-z^0-9]/_/g' | sed 's/á/a/g'
    Regards

  7. #7
    Just Joined!
    Join Date
    Jul 2007
    Posts
    4
    Cool thats it
    it worked fine

    just one tiny little problem

    i've got to predict all portuguese special chars, and they're quite a bit,
    but i can live with that

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...