I have the following data and want to change from Code 1 to Code 2. Is there any useful method to do that?

Code 1


Code 2

11130101, 11130102, 11130201
  • 1
    I presume there are more than three entries (with three entries, the fastest way is to do it by hand). The easiest way is probably a keyboard macro: do C-h i g (emacs)keyboard macros for information. Defining one to do it once can then be used with a numeric prefix to do it as many times as you want. They are useful to know about.
    – NickD
    Commented Apr 8, 2021 at 17:30
  • What @NickD said (please consider posting that as an answer).
    – Drew
    Commented Apr 8, 2021 at 17:48
  • Not directly answer but try to learn el-macro and how to save those macros which you do this will help and solve many of your problem. Commented Apr 10, 2021 at 8:52

1 Answer 1


You want to replace a newline with a comma and a space. You can use query-replace for that if you know how to type a newline character: C-q C-j. So all together, you can mark the region where you want to make the change and then type M-% C-q C-j RET , SPC RET !.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.