Announcement

Collapse
No announcement yet.

Windows XP batch file question

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Windows XP batch file question

    I am looking to create a batch file that will request a variable from user input, store it and use that variable to replace text in a file where the text to be replaced is a constant, (ie. imthesametext), to ease the overhead of an application rollout.

    The part where I am hung up is I need a scriptable command line utility, (preferably built into windows xp), that can find and replace text strings in a file.

    Can anyone recommend a good one thats not adware loaded?

    I have tried replace.exe, (not the system utility), a download found with google, that loads a webpage after each execution,

    and one called FR.exe that hangs after its operation is done waiting for the user to hit enter, so the user can read the website plugs the author compiled into it, also

    Also munge.exe is out, since I won't have the ability to install anything but our application and config files, and it does'nt seem to be available on all systems.

    So an executable that could be packaged in our installer that would run with out being "installed" is my only option besides a windows xp native app.

    Thanks in advance

  • #2
    Re: Windows XP batch file question

    Originally posted by georgeeye View Post
    I need a scriptable command line utility, (preferably built into windows xp), that can find and replace text strings in a file.
    VBScript is the built-in soluition for XP. The simplest case would be replace(), as is demonstrated in a Scripting Guy article. More complex replaces can be done via regular expressions.

    For unbuilt-in solutions, go with Powershell. Or whip one up with C#, wouldn't be too hard, would it ?-)

    -vP

    Comment


    • #3
      Re: Windows XP batch file question

      Originally posted by georgeeye View Post

      I have tried replace.exe, (not the system utility), a download found with google, that loads a webpage after each execution,
      since you are able to download things from net, here's a executable converted from Python (for Windows). Here's the source
      Code:
      import fileinput
      filename = raw_input("Enter filename: ")
      torepl = raw_input("Enter text to replace: ")
      repl = raw_input("Enter new text: ")
      for line in fileinput.FileInput(filename,inplace=1):
          line=line.strip()
          if torepl in line:
              line=line.replace(torepl,repl)
          print line
      usage:
      Code:
      C:\test>test.exe
      Enter filename: file.txt
      Enter text to replace: 1608
      Enter new text: 9999

      Comment


      • #4
        Re: Windows XP batch file question

        Thanks for the replies! I actually found a version of sed for windows that would run without install, and it was easier than writing something of my own since I already understand the syntax of sed.

        It can be found here by the way:

        http://unxutils.sourceforge.net/

        Comment

        Working...
        X