Results 1 to 9 of 9

Thread: Editing text file using a batch file

  1. #1
    Join Date
    May 2008
    Posts
    69

    Editing text file using a batch file

    Hi,

    I am new to batch files and I wanted to know how to use one to write information to a text file. I need to make a batch file to edit a "file" on several computers. The reason I put quotes around file is because it has no extension, such as .txt or .html. Is there any way to edit one using a batch file?

  2. #2
    Join Date
    Dec 2007
    Posts
    195

    Re: Editing text file using a batch file

    To write in a file text, you just need to redirect “>”:

    Code:
    echo text > output_file.txt

    To write in an existing file:

    Code:
    echo " Writing at the end of the file ">> output_file.txt

  3. #3
    Join Date
    May 2008
    Posts
    249

    Re: Editing text file using a batch file

    To Edit text file add the below lines to the end of a file :

    Code:
    echo text to add >> C:\WINDOWS\system32\drivers\etc\hosts

    Repeat for each host you want to add

  4. #4
    Join Date
    May 2008
    Posts
    209

    Re: Editing text file using a batch file

    Follow the steps below :

    • edit c:\[directory you want to edit] /s
    • Open up Notepad
    • Type the following code in:
    • @echo off
    • edittree [Your hard drive, usually C:]\[Directory you want to edit /s for quietly
    • Step 3: Save as "anyname.bat"

  5. #5
    Join Date
    Dec 2009
    Posts
    2

    sad Re: Editing text file using a batch file

    Quote Originally Posted by Mac-Imagery View Post
    To Edit text file add the below lines to the end of a file :

    Code:
    echo text to add >> C:\WINDOWS\system32\drivers\etc\hosts

    Repeat for each host you want to add

    ok but what if you latter decide you don't want that line of text, then how can you remove it?

  6. #6
    Join Date
    Dec 2009
    Posts
    23

    Re: Editing text file using a batch file

    Here is a more general approach. Put a list of hosts (or their ip addresses) in file C:/Hosts.txt.


    Code:
    # Script HostsScript.txt
    var str hostlist, host, path
    # Read the list of hosts.
    cat "C:/Hosts.txt" > $hostlist
    # Go thru the hosts one by one.
    while ( $hostlist <> "")
    do
        # Get the next host to process
        lex "1" $hostlist > $host
        # Create the path to file. It will be in one of the following two formats.
        # //host1/path/to/file
        # OR
        # //1.2.3.4/path/to/file
        set $path = "//"+$host+"/path/to/file"
        # Write string to file.
        echo "string to be added to file" > { echo $path }
    done

    Script is in biterscripting. Please test first. To test, save the script in file C:/Scripts/HostsScript.txt, then enter the following command in biterscripting.


    Code:
    script "C:/Scripts/HostsScript.txt"

    Of course, you need to have access permissions to the path on each of the hosts.

  7. #7
    Join Date
    Dec 2009
    Posts
    2

    sad Re: Editing text file using a batch file

    i wanted to know if there was a script to delete the added hosts from the hosts file using a batch file, I was not looking for another script to add them to the file...

  8. #8
    Join Date
    May 2008
    Posts
    2,012

    Re: Editing text file using a batch file

    Hi,
    Batch files are the executable files, on windows operating system. Do you want to run a another file, whose code is written in that batch file. Is this what you want? I will explain you in a simple way what the batch files do, suppose you enter any command in the terminal to open a program, the same can be done with out running the command in the terminal. Just edit the notepad file and insert the command which you have entered in the terminal. Then save the file with .bat extension.

  9. #9
    Join Date
    Mar 2010
    Posts
    1

    Re: Editing text file using a batch file

    to add and remove the line in hosts file, uu can easily use proxyblocker, its free, just google it with keyword 'proxyblocker beta'.


    sch

Similar Threads

  1. DSMOD from batch and text file
    By BUKSIS in forum Active Directory
    Replies: 2
    Last Post: 03-03-2010, 10:07 PM
  2. Server config file - batch editing script
    By ranjankumar09 in forum Windows Software
    Replies: 3
    Last Post: 28-01-2010, 10:30 PM
  3. Editing text file through FTP, SSH, SCP
    By Kingfisher in forum Windows Software
    Replies: 5
    Last Post: 05-01-2010, 11:21 AM
  4. Replace text string using batch file
    By jean-paul martell in forum Operating Systems
    Replies: 2
    Last Post: 23-06-2009, 01:18 PM
  5. Batch Script Text file parse
    By tator.usenet@gmail.com in forum Windows Server Help
    Replies: 5
    Last Post: 25-03-2009, 02:12 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,064,823.44031 seconds with 17 queries