Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete Duplicate Line Function that Ignores 1st 18 Characters 1

Status
Not open for further replies.

zoodaddy

Technical User
May 13, 2010
10
US
I Need a Delete Duplicate Line Function that will Ignore the first 18 Characters of each line
I have found many and excellent examples in deleting the whole line but can't figure how to filter the 1st 18 characters.
Example below is from a Log.inf file showing that the first 3 lines repeat but with different time stamps
Can anyone please help.

(Color just for Emphasizes)

6-09-10 0:01:37>Fault= PLC fault with Option to processed operator post tires [1308]
6-09-10 0:01:37> Bar Code Post - PLC fault
6-09-10 0:01:37> Group PLC faulted in step [9004]
6-09-10 0:16:19> Fault= PLC fault with Option to processed operator post tires [1308]
6-09-10 0:16:19> Bar Code Post - PLC fault
6-09-10 0:16:19> Group PLC faulted in step [9004]
6-09-10 0:16:21> Fault= PLC fault with Option to processed operator post tires [1308]
6-09-10 0:16:21> Bar Code Post - PLC fault
6-09-10 0:16:21> Group PLC faulted in step [9004]
6-09-10 0:46:52> Fault= PLC fault with Option to processed operator post tires [1308]
6-09-10 0:46:52> Bar Code Post - PLC fault
6-09-10 0:46:52> Group PLC faulted in step [9004]

Just need:
6-09-10 0:01:37>Fault= PLC fault with Option to processed operator post tires [1308]
6-09-10 0:01:37> Bar Code Post - PLC fault
6-09-10 0:01:37> Group PLC faulted in step [9004]


 
how to filter the 1st 18 characters
strFilteredLine = Mid(strWholeLine, 19)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
How do you count the 18? You make liberal typing of spaces. Could it be more rigorous? Make up a more generic criteria?
 
I'd use something like this:
strFilteredLine=Mid(strWholeLine,1+InStr(strWholeLine,">"))

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
That's what I am leading to, but still the op types a space or no space after > sign if it is at his will.
 
Do you always have the ">" character after the timestamp? If so, you could split the string there and compare what follows. This will be more flexible when the date stamp changes to a 2 digit month.
 
Code:
Trim(strFilteredLine)
Could be added to get rid of any spaces.
 
That is why you've to make the intention clear to formulate the question, for op's own sake. How do you know the single space has no meaning? Or the multiple space for Bar... line? Trim means trim _all_ spaces.
 
The way I understand the situation is: Log only unique error codes, if the same error happens at a different time stamp, ignore it. Spaces seem to be irrelevant.
 
With all those "assumptions", the script would look something like this. (I can imagine some fringe cases to make undesirable result, but... there is always something more to desire of.)
[tt]
datafile="c:\xyz\pqr.txt"
outputfile="c:\xyz\stu.txt"

set fso=createobject("scripting.filesystemobject")
if not fso.fileexists(datafile) then
set fso=nothing
wscript.quit 99
end if

set ots=fso.opentextfile(datafile,1)
set odic=createobject("scripting.dictionary")
do while not ots.atendofstream
s=ots.readline
skey=trim(mid(s,instr(1,s,">",1)+1))
if not odic.exists(skey) then
odic.add skey, s
end if
loop
ots.close
set ots=nothing

set ots=fso.opentextfile(outfile,2,true)
if odic.count<>0 then
for each key in odic.keys
ots.writeline odic(key)
next
end if
ots.close
set ots=nothing
set fso=nothing
[/tt]
 
Tsuji It worked !
Thanks

Spaces doesn't matter.
My error on first line.
there is always a space after ">"
Time format is always 18 Characters
Fault Description starts after ">"
Their just happens to be a Space at the begining of the
Fault Description. and time stamp :)

" 6-08-10 12:29:44>"

Thanks to Everyone !
I am Understanding
CreateObject("Scripting.Dictionary") a little Betterow.
I will endeavor to be better at presenting my problems.
 
A star for tsuji, your technique of using the dictionary object to return unique values will be of value to me in some scripts I currently have.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top