I am trying to use sublime's text search and replace function and regex to match a string of number in each line and append a comma to each. So here's the sample file:
273794103 418892296 134582886 380758661 109829186 248050497 2167935715 374858669
I want this to be:
273794103, 418892296, 134582886, 380758661, 109829186, 248050497, 2167935715, 374858669,
I tried doing this (\d+)\n
and replacing it with $1,
but this doesn't work. Any idea why? FYI for those who are not into sublime but into regex, Sublime Text uses Python's regex engine.
Select all by pressing CTRL+A (or Command+A for Mac). From Selection, choose Add Cursors to Line Ends by pressing SHIFT+ALT+I (or SHIFT+OPTION+I). Type the Comma character.
To add comma to any line
Select the lines you want to modify
CTRL + SHIFT + L
RIGHT_ARROW
COMMA
Using ctrl + shift + L is how you can modify all selected lines. Very handy :-)
I'd recommend this
'Find What': $
// matching all ends of your lines
'Replace With': ,
// replaces all line ends with a coma
this will work with any file :-)
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