I am struggling with formatting of a db2 query. I would like to replace 2 or more spaces in a string with a semicolon. I know how to do it with all spaces, the question would be how to change only 2 or more spaces :P
Here is an example, i would like to change this:
john doe 1900-01-01 california
to
john doe;1900-01-01;california
The problem is that i have one space in the name field, so i can't use a simple tr command. In my real job, there can be a single space in any field.
I would appreciate your help very much! Thanks in advance!
$ sed 's/ */;/g'
john doe 1900-01-01 california
john doe;1900-01-01;california
one space two spaces three spaces
one 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With