Change two or more spaces to a single semicolon Change two or more spaces to a single semicolon shell shell

Change two or more spaces to a single semicolon


$ sed 's/   */;/g' john doe   1900-01-01  california john doe;1900-01-01;california one space  two  spaces   three    spacesone space;two;spaces;three;spaces


Try using

sed -i 's/   */\;/g' your-file

This will substitute every 2 or more spaces with a ; in the file you pass it.


The best way is to query your database tables with the proper delimiter (ie ";"). See if you can do it that way. Otherwise,

$ echo "john doe 1900-01-01 california" | sed 's/ /;/2g'john doe;1900-01-01;california

This will break if the name has 3 or more words.