Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 23-06-2009
Member
 
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?
Reply With Quote
  #2  
Old 23-06-2009
Member
 
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
Reply With Quote
  #3  
Old 23-06-2009
Member
 
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
Reply With Quote
  #4  
Old 23-06-2009
Member
 
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"
Reply With Quote
  #5  
Old 06-12-2009
Member
 
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?
Reply With Quote
  #6  
Old 21-12-2009
Member
 
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.
Reply With Quote
  #7  
Old 14-01-2010
Member
 
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...
Reply With Quote
  #8  
Old 15-01-2010
Member
 
Join Date: May 2008
Posts: 2,008
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.
Reply With Quote
  #9  
Old 09-03-2010
Member
 
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 08:12 AM.