• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Search

spaces

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.txt

tr -s '[:blank:]' ', ' < input.txt > output.txt

It’s perfect for creating a comma delimited file for importing to Excel.

Filed Under: Linux Tagged With: bash, commas, file, input, output, replace, spaces

Replace spaces with comma

February 4, 2020

Here’s a simple sed command to replace multiple spaces into a comma delimited file.

sample.txt

one       two
three     four

one two three four

The sed command.

sed 's/ \+ /,/g' sample.txt > sample2.txt

sed 's/ \+ /,/g' sample.txt > sample2.txt

sample2.txt

one,two
three,four

one,two three,four

Filed Under: Linux Tagged With: comma, find, replace, sed, spaces, tab

  • Home
  • About
  • Search

Copyright © 2023