How do i replace multiple spaces with one space using sed?



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

    The sample file being used:

    This is my first IP 10.50.20.1
    grapes
    apples
    pears
    This is      the first block
    oranges
    PLUMS
    
    This is my second IP 10.50.20.2
    This is my duplicate IP 10.50.20.2
    grapes
    apples
    pears
    This is      the second block
    oranges
    PLUMS
    
    This is my third IP 10.50.20.3
    grapes
    apples
    pears
    This is the third       block
    oranges
    plums
    

    Replace multiple spaces with one space.

    $ sed 's/[[:space:]]\+/ /g' samplefile
    


© Lightnetics 2024