How to Use Variables in Sed on Windows?
I'm Writing a Batch Script to Automate Build Events on Windows, and as Part of It I Need to Change Some Lines in a Few Files. So I'm Going to Use Sed. but How...
I'm writing a batch script to automate build events on Windows, and as part of it I need to change some lines in a few files. So I'm going to use sed. But how do I use variables in sed inside a batch script?
1 Answer
Refer to the variables using the usual %varname% syntax used by cmd.exe. As shown in this example, I've defined two variables old and new and substituted them into a sed expression on the command line. Typing original into the input, sed echos back new and improved.
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
c:\Users\Nicole>set old=original
c:\Users\Nicole>set new=new and improved
c:\Users\Nicole>sed "s/%old%/%new%/"
original
new and improved
^Z