Hello,
How do I go about writing a script that will edit multiple text files? This is to be performed on 4 different servers that are Dell 1850's running Win Server 2003. Files extensions such as *.htm, *.ini, and *.xml. Actions would be mostly find/replace text strings and adding/removing comments. Some I'm sure there is a means to accomplish this and I am hoping this is the right place to ask.
Holler if more info is needed.
Thanks in advance
Fred
Hi Freondude,
|
Definitely use biterscripting ( http://www.biterscripting.com ) . Here is a sample script - it will replace all "ABC" in files *.html to "XYZ".
|
Hi Newboy:
# Script Microsoft2Yahoo.txt
# .html files are in folder C:/abc. Collect a list of them.
var str list ; lf -n "*.html" "C:/abc" > $list
# Process files one by one.
while ( $list <> "")
do
# Get the next file.
var str file ; lex "1" $list > $file
# Read file contents into a string variable.
var str content ; cat $file > $content
# Keep replacing "www.micosoft.com" with "www.yahoo.com" until there are
# no more instances left of "www.micosoft.com".
while ( { sen -c "^www.micosoft.com^" $content } > 0 )
sal "^www.micosoft.com^" "www.yahoo.com" $content > null
# All instances are replaced. Write file back.
echo $content > { echo $file }
done
Save the script as C:/Scripts/Microsoft2Yahoo.txt, start biterscripting ( http://www.biterscripting.com ) , enter the following command. script "C:/Scripts/Microsoft2Yahoo.txt" We are using the file-directory-loop to loop thru files, the sen (string enumerator) command to count instances of "www.microsoft.com" in a string, and the sal (string alterer) command to replace "www.microsoft.com" with "www.yahoo.com". Help on all of these is available at that web site. (It might help to learn a bit of biterscripting if you plan on automating things of this nature in the future. They have some good tutorials posted on their site.) Sen |