Bash Replace Spaces with a Comma May 8, 2023 Replace spaces with commas from one file and send the output to another file. tr -s '[:blank:]' ', ' < input.txt > output.txttr -s '[:blank:]' ', ' < input.txt > output.txt It’s perfect for creating a comma delimited file for importing to Excel.