You are here:
How to replace string patterns on multiple files using emacs?

How to replace string patterns on multiple files using emacs?

Using emacs can be of great help to achieve this. Follow the following steps:

  1. Open emacs from the directory that you want to replace the string patterns
  2. Press C-x C-f (C = Control)  (press enter)
  3. Select those files where you want to replace the strings by pressing 'm' (use 'u' to unmark them)
  4. Once all the files have been marked, press 'ESC' followed by 'x', then type 'dired-do-query-replace-regexp'. 
  5. Now, enter the string you want to replace (press enter) and then enter the new string (press enter)
  6. Emacs will stop and show you whenever a match occurred. Press 'y' to replace it or 'n' to skip it
  7. To save the data, press 'ESC' followed by 'x'. Then type 'ibuffer' (press enter). Type '*u' to mark all the unsaved data. Finally, press 'S'
  8. To exit, press C-x C-c