Just use tr command for this purpose: tr -s '[[:punct:][:space:]]' ' ' Example for cat file.txt | tr -s '[[:punct:][:space:]]' ' '