|
| |||||||||
| Tags: batch file, text file |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| ||||
| ||||
| 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
| ||||
| ||||
| 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
| ||||
| ||||
| 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
| ||||
| ||||
| Re: Editing text file using a batch file
Follow the steps below :
|
|
#5
| |||
| |||
| Quote:
ok but what if you latter decide you don't want that line of text, then how can you remove it? |
|
#6
| |||
| |||
| 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
| |||
| |||
|
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
| |||
| |||
| 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
| |||
| |||
| 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 |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Editing text file using a batch file" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| DSMOD from batch and text file | Pete Jones | Active Directory | 3 | 04-03-2010 01:42 AM |
| 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 02:18 PM |
| Batch Script Text file parse | tator.usenet@gmail.com | Windows Server Help | 5 | 25-03-2009 03:12 AM |