As I have to deal with the plain text file in Windows and I want to solve this issue with elegant behavior, I know I need to choose the tool Vim or Emacs. This time, the Windows platform has helped me make my decision, the Emacs. Comparing with Vim, I think there’s much less deployment part to start my work.

I won’t finish this post at once. In fact, I prepare to add contents in this post as I learned new skills of Emacs.

Replace String

Here I need to replace the newline with space, and replace XXX: as [newline]XXX:.

M-x replace-string C-q C-j RET [Space] RET
  • C-q Cj represents newline.
  • RET represents keyboard Enter
  • [Space] just as keyboard Space

Special characters:

  • FF, page break: C-q C-l.
  • Br.

Search Text in Multiple Files

Use one complicated command as example. Search text line with <xsl:output but exclude UTF-8 in all *.xsl or *.XSL files. In fact, here we just use the Unix command to finish our task in Emacs. You need to use M-! to enter the shell mode.

find . -type f -iname "*.xsl" -print0 | xargs -0 -e grep -nH -e "<xsl:output" | grep -v "UTF-8"

This complicated command contains 4 parts: find, xargs, grep and grep.

  • find part: search file type under . folder, with case insensitive name *.xsl. Output with -print0 option, which will be used in xargs -0.
  • xargs part: construct parameter for the following grep. Use -0 option to deal with file name containing space or other special characters.
  • 1st grep part: search text <xsl:output.
  • 2nd grep part: ignoring text UTF-8.

Also, if you only want to search *.xsl file containing <xsl:output text, you can just use Emacs command rgrep directly. You need to press M-x and then type rgrep.