How do i replace a work using pattern matching brackets in sed?



  • Man page for sed: https://www.lightnetics.com/post/3334

    Using the sample file:

    cat linefile 
    This is line one
    
    This is line two
    
    This is line three
    

    We want to change the word three to 3.

    Use this, this is more specific than using the dot to match any character.

    $ sed 's/[Tt]hree/3/g' linefile
    

    Result:
    This is line one

    This is line two

    This is line 3

    More accurate use of the dot.

    $ sed 's/[Tt]..ee/3/g' linefile
    

    Result:
    This is line one

    This is line two

    This is line 3



© Lightnetics 2024