nhrt

nhrt (nhutils replace text) is a console utility to replace text in files or in stdin stream:

  • searches for plain text or ECMAScript regular expression
  • replaces text with static text or a formatted regular expression
  • supports escape characters
  • bulk operations – multiple search/replace sets in one session
  • multiple code pages
  • lightweight portable utility without dependencies on other software components
  • intended for using in batch files – all the parameters can be specified through command line arguments.

And it’s is free!

Code pages supported

nhrt can also be used to convert code pages of text files while supporting following code pages:

  • ANSI
  • OEM
  • Unicode (UCS-2),
  • UTF-8,
  • any Windows supported code page specified by its number like CP 1252 for Western (French, German etc).

nhrt can convert code page at the same time when replacing text for example it can read a utf-8 file, then replace text strings in it, then save the file in Unicode (utf-16).

nhrt is able to process files with different code pages in one action for example to insert text from an OEM file into a Unicode file.

Using in batch files or scripts

nhrt utility designed for being used in BAT/CMD batch files, JS/VBS scripts, PowerShell, and other programs:

  • all the settings specified with command line arguments
  • no interactive input from user required
  • wildcards ? and * supported in file names to process many files at a time
  • recurse subdirectories option

nhrt works in Windows XP, Windows Vista, Windows 7, Windows 8, Windows 10 Desktop. The utility is just binary. No installation required. No software components or libraries required.

See also

help on nhrt | questions and answers on nhrt | support forum

Some examples of using nhrt

See examples of using nhrt: replacing with static text, replacing with file content, batch file to compose a html file from text fragments.

Searching with a regular expression and replacing with static text

Replacing year 2000-2019 to 01.03.2009 in all *.txt and *.cmd files:

nhrplc -sre:"[0-3]?[0-9]\.[0-1]?[0-9].20[0-1][0-9]" -t:"01.03.2009" *.txt *.cmd

First argument specifies a regular expression to search. Expected date format is d.M.yyyy.

Second argument specifies a static text for replacement.

Third and fourth arguments specify files to process.

Searching for a text and replacing with a file content

How to replace text string ref1 with content of file content1.txt in all html files:

nhrplc -s:"ref1" -f:content1.txt *.htm *.html

First argument specifies static string ref1 to search for.

Second argument specifies file content1.txt.

Third and fourth arguments specify files to process – all htm и html files.