scripts that do stuff

Friday, May 7, 2010

Merge two files that have the same amount of lines (VBS)

I needed a quick and dirty way to take two files with different content, but the same AMOUNT of content, and combine them into one file with File A's contents and File B's contents combined on the same corresponding line.

Here's what I came up with (I'm sure there are better ways, but hey, like I said, I'm not that great!)

Const ForReading1 = 1
Const ForReading2 = 1


DIM NEWID, OLDID, TS, TS2, NEWLINE, OLDLINE


set ACT=CreateObject("Wscript.shell")
set FSO=CreateObject("Scripting.FileSystemObject")
NEWID = "FileA.txt"
OLDID = "FileB.txt"


set TS = FSO.OpenTextFile(OLDID, ForReading1)
set TS2= FSO.OpenTextFile(NEWID, ForReading2)


set objMerged=FSO.CreateTextFile("mergedfiles.txt",8)


Do until TS.AtEndOfStream
OLDLINE = TS.READLINE
NEWLINE = TS2.READLINE


objMerged.WriteLine(NEWLINE & "," & OLDLINE)


Loop
TS.Close
TS2.Close
objMerged.close

Let me clear my throat.

Yeah, I'm just getting started here.

I'm not a very good programmer. I have been known to put together some pretty ridiculous solutions for issues though, and I thought I'd share some of them. 99.99% of the scripts that I write are in batch or vbs. I work in an all windows environment, and 99.9% of the scripts are designed around XP / Server 2003.

Just a few areas that I'm playing with at the moment:
  • XML
  • String Manipulation
  • Scheduled Task monitoring and manipulation
  • WMI/WMIC integration
  • Active Directory
  • SQL
  • SNMP

I usually write these things to operate on a grand scale for an enterprise network. I will probably be posting limited examples of the code just to highlight some of the trickier parts, but I'm not saying that some of the complete examples won't find their way to the site. There are usually MANY moving parts, and I heavily rely on Microsoft's fairly recently acquired pstools suite in many of these programs.

Some of the things that I've done include:

-Scheduled task monitoring with status reporting to sql (Solarwinds' "Orion" software, but could be adapted for others)

-Automated, Active Directory-based file distribution using only one computer per site to push the initial files, then initiating a push from that computer to send to the other computers at the particular site. So, if you have 200 sites, each with 10 computers, you're looking at 2000 total computers. With a 100MB file, you're looking at 200GB of data transfer. With this script, that would be cut down to only 2GB.

-remote installation/un-install of software on enterprise-wide scale, simultaneously.

and more...

So stay tuned..

Also, I'm pretty good at coming up with solutions to problems. If you want me to take a try at solving your issue, email me: L3it3r@gmail.com We'll come to some kind of agreement :)