Skip to main content

Converting spaces in a text file to periods/full stops [Resolved]

I'm quite new to Linux so forgive my ignorance.

I have a regular text file with plain text. I would like to know if it's possible to convert all the spaces within the file to periods/full stops.

For example, "The rain is relentless" to ""

The text file is quite large so it would be remiss of me not to put it to the forum.

Thanks very much.

Question Credit: aomine_daiki
Question Reference
Asked October 15, 2017
Posted Under: Unix Linux
2 Answers

Try this:

sed -i 'y/ /./' file

With '-i' the file is overwritten with the new replacements. Without '-i' the file is not changed, the replacements are printed to the terminal.

credit: seshoumara
Answered October 15, 2017
awesome, thank you very much! – aomine_daiki yesterday
 CanDoerz  1 year ago

Many tools can do that, e.g. sed:

sed 's/ /./g' file

or tr:

tr ' ' . <file

credit: jimmij
Answered October 15, 2017
Thank you, this indeed did work. Although didn't overwrite - as seshoumara mentioned below I needed the -i. – aomine_daiki yesterday
 CanDoerz  1 year ago
Your Answer