Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: batch for using 2 txt files  (Read 3843 times)

0 Members and 1 Guest are viewing this topic.

Blisk

    Topic Starter


    Intermediate

    Thanked: 1
    • Experience: Familiar
    • OS: Windows 7
    batch for using 2 txt files
    « on: April 27, 2017, 08:39:33 AM »
    I am trying to make a batch file which will take a comand line from text file and computer name to execute command.
    But all what I succed is to take text from first file.

    In first.txt I have this line
    first.txt
    copy /Y \\server1\Users\%computername%\john\deltmp.txt c:\logs\deltmp.txt

    copy.bat
    Echo %computername%>>C:\Users\Admin\test\computername.txt
    for /f "delims=" %%a in (C:\Users\Admin\test\first.txt) do %%a


    When I execute copy.bat I get error
    The system cannot find the path specified.
            0 file(s) copied.

    because variable %computername% is not recognised from first.txt file
    how to read computername so batch will copy that file.
    I have created a file computername.txt to read from that file but don't know how to implement that in batch.

    And I need it separately batch and first.txt file, because first.txt changes as needed

    Blisk

      Topic Starter


      Intermediate

      Thanked: 1
      • Experience: Familiar
      • OS: Windows 7
      Re: batch for using 2 txt files
      « Reply #1 on: April 29, 2017, 12:03:18 PM »
      I found a solution with fart
      https://sourceforge.net/projects/fart-it/
      small program for find and replace

      Geek-9pm


        Mastermind
      • Geek After Dark
      • Thanked: 1026
        • Gekk9pm bnlog
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: batch for using 2 txt files
      « Reply #2 on: April 29, 2017, 02:58:43 PM »
      Glad you found the answer that works for you.
      The fart.exe is a program based on UNIX stuff. It is like grep, a standard UNIX utility.

      Windows users might prefer to use Powershell instead.
      Look at this post about fart:
      http://lifehacker.com/354546/find-and-replace-text-with-fart
      Notice the third comment:
      Quote
      why waste time on this when you got powershell?
      to do a search:
      select-string {pattern} {filename}
      to do a replace:
      $content = get-content {filename}
      $content -creplace "searchtext","replacetext" | set-content {filename}
      regular expressions are supported in search patterns.
      you do this and so much more. Powershell rules.
      Powershell Tutorials are available.
      https://mva.microsoft.com/en-us/training-courses/getting-started-with-powershell-3-0-jump-start-8276