Text editor to search/replace newlines and tabs

A time-saving feature I often used while editing large text files (the kind used for batch processes of data exchanges, aka, "flat files" for feeds between multiple systems) was Notepad++'s extended Find/Change function where you can specify certain characters (such as tab, space, line feed, carriage return) in both the Find function and the Change function.

This is the detail on how it works:

Open the find/replace dialog. At the bottom will be some Search mode options. Select "Extended (\n \r \t \0 \x...)" In either the Find what or the Replace with field entries, you can use the following escapes:

  • \n new line (LF)
  • \r carriage return (CR)
  • \s space character
  • \t tab character

This would make it very easy to edit lists of information, changing files from comma to tab delimited, or files with spaces between into comma delimited, as well being easy to go from spaces to tabs (or visa versa).

Anyone happen to know which text editors running on Mac OS have this feature (or have plugins to add this functionality)?


Solution 1:

Text Edit which is available out of the box supports searching for special characters:

  • Access "find" functionality with Cmd-F
  • Click the small magnifying glass at the beginning of the entry field and select "Insert Pattern" (last entry)
  • Pick your pattern (and repeat if necessary)

enter image description here

  • Move the cursor to the replacement field to select a pattern there (or just copy/paste from the search field)

If you do a lot of text-based file processing it might help to spend some time to learn about basic Unix tools like awk, sed and friends. This would make thinks a lot easier on the long run.

Solution 2:

I was using TextEdit on a Mac, and nohillside's solution didn't work for me because I needed to replace with a tab, not search for a tab. What worked for me was hitting option + tab in the "replace" field.