Replace a number string in the log and mask part of it

I have entry in the log which reads:
GetTagNo,data,value,123456789

I need to be able to have a script which runs everynight on the daily log at midnight:
for example log2010-03-31.txt and replaces the above string such that this particular entry gets masked:
GetTagNo,data,value,XXXXX6789

The script should replace only toddays log: For example logYYYY-MM-DD.txt and then look for the above pattern

The no string can be 5 to 15 digits long.

Can anybiody suggest a vbscript that can be run as aschedule task to do this?
rheasamAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

exx1976Commented:
I can write one for you.  A couple questions:

Is the number always the last field?

How many digits do you want to remain unmasked?
0
rheasamAuthor Commented:
Yes, the no is always the last field.
Ok, the no of digits can vary. It can be from a 5 digit to 15 digit no. We just need the last 4 to be un masked and rest masked.
0
sr75Commented:
The masking part is easy.  Here is how I would do it.  One solution will preserve the length and the other will mask that as well:

---------------------------------------
       Solution 1 Preserve Length
---------------------------------------
str2Mask = "GetTagNo,data,value,123456789"
arr2Mask = split(str2Mask, ",")
str2Mask = arr2Mask(3)
For i = 0 to len(str2Mask) - 4
     strMask = strMask & "X"
Next
strMask = strMask & right(str2Mask, 4)

---------------------------------------
     Solution 2 Predefined Length
---------------------------------------
str2Mask = "GetTagNo,data,value,123456789"
arr2Mask = split(str2Mask, ",")
strMask = "XXXXXXXXXXX" & right(arr2Mask(3), 4)

Open in new window

0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

exx1976Commented:
Try this.
SourceFilePath = "c:\logs"
DestinationFilePath = "c:\masked"
Set oFS = CreateObject("Scripting.FileSystemObject")
FileName = "\log" & Year(Now) & "-" & Right("0" & Month(Now),2) & "-" & Right("0" & Day(Now),2) & ".txt"
SourceFile = SourceFilePath & FileName
DestinationFile = DestinationFilePath & FileName
Set oSource = oFS.OpenTextFile(SourceFile)
Set oDest = oFS.CreateTextFile(DestinationFile)
Do While Not oSource.AtEndOfStream
	data = oSource.ReadLine
	mask = ""
	output = ""
	MyArr = Split(data,",")
	unmask = MyArr(UBound(MyArr))
	For i = 1 To Len(unmask)-4
		mask = mask & "X"
	Next
	mask = mask & Right(unmask,4)
	MyArr(UBound(MyArr)) = mask
	For q = 0 To UBound(MyArr)
		output = output & MyArr(q) & ","
	Next
	output = Left(output,Len(output)-1)
	oDest.WriteLine(output)
Loop
oSource.Close
oDest.Close

Open in new window

0
rheasamAuthor Commented:
Ok, thanks. For example here are my log entries:

are
Ok, the string is not constant, it is part of log and there may be several such string occurences on dif flines with varying length of nos. For example....
.........
test123
GetTagNo,data,value,123456789
test1234
test1235
GetTagNo,data,value,987654321
test1234
test1235
....................


the resulting new log should look:
.........
test123
GetTagNo,data,value,XXXXX6789
test1234
test1235
GetTagNo,data,value,XXXXX4321
test1234
test1235
....................


0
rheasamAuthor Commented:

exxx1976, Thaks your reply.
where is the part in the source code where you look for the string:GetTagNo
We should be able to define the lines containing only certain strings
We do not want to replace nos on each and every line.
0
exx1976Commented:
Sorry man, you should have written your original request a bit more clearly then.  I don't have time to rewrite this right now, maybe in a few days.
0
sr75Commented:
add these lines to exx1978's script:

On Line 11:    

 If instr(data, GetTagNo) then

Just above the LOOP on Line 25

End If

0
sr75Commented:
I should have read your expected output.

Change the Do While Loop to the attached and it should present that to you.

Do While Not oSource.AtEndOfStream
        data = oSource.ReadLine
	If inStr(data, "GetTagNo") then
        	mask = ""
        	output = ""
        	MyArr = Split(data,",")
        	unmask = MyArr(UBound(MyArr))
        	For i = 1 To Len(unmask)-4
        	        mask = mask & "X"
        	Next
        	mask = mask & Right(unmask,4)
        	MyArr(UBound(MyArr)) = mask
        	For q = 0 To UBound(MyArr)
                	output = output & MyArr(q) & ","
        	Next
        	output = Left(output,Len(output)-1)
	Else
		output = data
	End If
        oDest.WriteLine(output)
Loop

Open in new window

0
rheasamAuthor Commented:
Thanks SR and exxx. Let me test this and get back to you.
0
exx1976Commented:
@ sr75 - That won't work.  You're going to get errors generated by the fact that the split function isn't going to create an array (the one I'm manipulating the whole rest of the way through), so it's going to blow up.

The whole thing needs to be rewritten.

Also, come to think of it, the array should be reinitialized every line..  I overlooked that originally.


OP - Either way, that's the code that solves the original request.  Do with it what you will.
0
exx1976Commented:
That should work.
0
exx1976Commented:
Not how I would have done it, but quick & elegant.  I like it.  :)


OP - next time state all your requirements up front, *correctly*..
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rheasamAuthor Commented:
testing it now.  I will update further tomorrow and will promptly award you the points after a succesful test.
0
rheasamAuthor Commented:
Guys, give me till Mon for final confirmation and will def award you points on Mon.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.