0

I'm trying to find a simple/elegant command-line solution for a process that is often used in scripts. Something like: (Fictional example)

CopyWithReplace <SourceFile> <DestFile> -m <match regular expression> -r <replacement regular expression>

It would copy the text file with the matched text replaced as specified. Ideally, the find/replace would happen in the pipeline, rather than as a secondary step. (Destinations quite often are remote locations, and long distance WAN links are often not as fast and reliable as desired.)

What would be the simplest** way to achieve this scriptable functionality in a windows environment?

** Simplest = easy to write batch code, fewest 3rd party tools, etc. Bonus points for a reasonably standard Regex implementation.

SvdSinner
  • 951
  • 1
  • 11
  • 23

1 Answers1

0

This can be achieved with sed.

The basic usage pattern, for a substitution as you described, is:

sed 's/regexp/replacement/g' inputFileName > outputFileName

sed is a Unix utility, but there are several ways of using it in Windows if you wish. This StackOverflow post lists the various options available.

Community
  • 1
  • 1
Tom Lord
  • 27,404
  • 4
  • 50
  • 77