EDN Admin
Well-known member
I have two text files as follows:<br/>
<br/>
File1:<br/>
<br/>
AC1-0002A,Jukebox,1149473,Marked Full,202,M,0,,0,0<br/>
AC1-0003A,Jukebox,1260463,Marked Not Full,204,M,0,,0,0<br/>
AC1-0003B,Jukebox,1258468,Marked Full,205,M,0,,0,0<br/>
AC1-0001A,Jukebox,1111111,Marked Not Full,201,M,0,,0,0<br/>
AC1-0004A,Jukebox,1258439,Marked Full,206,M,0,,0,0<br/>
AC1-0005A,Jukebox,221460,Marked Not Full,208,M,0,,0,0<br/>
AC1-0005B,Jukebox,546985,Marked Not Full,209,M,0,,0,0<br/>
AC1-0006A,Jukebox,1258468,Marked Not Full,211,M,0,,0,0<br/>
<br/>
<br/>
File2:<br/>
<br/>
AC1-0002A,Jukebox,1149473,Marked Full,202,M,0,,0,0<br/>
AC1-0003A,Jukebox,1262454,Marked Not Full,204,M,0,,0,0<br/>
AC1-0003B,Jukebox,1258468,Marked Full,205,M,0,,0,0<br/>
AC1-0004A,Jukebox,1258439,Marked Full,206,M,0,,0,0<br/>
AC1-0004B,Jukebox,221460,Marked Not Full,208,M,0,,0,0<br/>
AC1-0005B,Jukebox,547234,Marked Not Full,209,M,0,,0,0<br/>
AC1-0006A,Jukebox,1260231,Marked Not Full,211,M,0,,0,0<br/>
AC1-0006B,Jukebox,1258468,Marked Not Full,211,M,0,,0,0<br/>
<br/>
<br/>
Expected result:<br/>
<br/>
AC1-0003A,Jukebox,1260463,Marked Not Full,204,M,0,,0,0,AC1-0003A,Jukebox,1262454,Marked Not Full,204,M,0,,0,0<br/>
AC1-0001A,Jukebox,1111111,Marked Not Full,201,M,0,,0,0,,,,,,,,,,<br/>
AC1-0005A,Jukebox,221460,Marked Not Full,208,M,0,,0,0,,,,,,,,,,<br/>
AC1-0005B,Jukebox,546985,Marked Not Full,209,M,0,,0,0,AC1-0005B,Jukebox,547234,Marked Not Full,209,M,0,,0,0<br/>
AC1-0006A,Jukebox,1258468,Marked Not Full,211,M,0,,0,0,AC1-0006A,Jukebox,1260231,Marked Not Full,211,M,0,,0,0<br/>
,,,,,,,,,,AC1-0006B,Jukebox,1258468,Marked Not Full,211,M,0,,0,0<br/>
<br/>
<br/>
I have come up with follows, but not getting the expected result:<br/>
<br/>
strHeaderFile = "File1"<br/>
strOrderFile = "File2"<br/>
strOutputFile = "RESULT.TXT"<br/>
strContents = ""<br/>
Const intForReading = 1<br/>
Set objFSO = CreateObject("Scripting.FileSystemObject")<br/>
Set objHeaderFile = objFSO.OpenTextFile(strHeaderFile, intForReading, False)<br/>
While Not objHeaderFile.AtEndOfStream<br/>
strHeaderLine = objHeaderFile.ReadLine<br/>
strHeaderOrdNum = Split(strHeaderLine, ",")(0)<br/>
strVolStatN = Split(strHeaderLine, ",")(3)<br/>
Set objOrderFile = objFSO.OpenTextFile(strOrderFile, intForReading, False)<br/>
While Not objOrderFile.AtEndOfStream<br/>
strOrderLine = objOrderFile.ReadLine<br/>
strOrderOrdNum = Split(strOrderLine, ",")(0)<br/>
strVolStatO = Split(strOrderLine, ",")(3)
<br/>
<br/>
==============================================================<br/>
If strOrderOrdNum = strHeaderOrdNum and strVolStatN = "Marked Not Full" Then<br/>
<br/>
If strContents = strOrderLine Then<br/>
<br/>
strContents = ""<br/>
Else<br/>
strContents = strContents & VbCrLf & strOrderLine & "," & strHeaderLine<br/>
End If <br/>
<br/>
Else <br/>
<br/>
If strHeaderOrdNum <> strOrderOrdNum Then <br/>
If strContents <> null Then
<br/>
strContents = strContents & VbCrLf & strOrderLine & ",,,,,,,,,"
<br/>
else
<br/>
strContents = nothing<br/>
end if<br/>
End if<br/>
<br/>
End If<br/>
=======================================================================================
<br/>
<br/>
Wend<br/>
<br/>
<br/>
objOrderFile.Close<br/>
Set objOrderFile = Nothing<br/>
Wend<br/>
wscript.echo strContents <br/>
objHeaderFile.Close<br/>
Set objHeaderFile = Nothing<br/>
<br/>
Now output the final file<br/>
Set objOutputFile = objFSO.CreateTextFile(strOutputFile, True)<br/>
objOutputFile.Write strContents<br/>
objOutputFile.Close<br/>
Set objOutputFile = Nothing<br/>
Set objFSO = Nothing<br/>
<br/>
Please help me out.<br/>
Thanks<br/>
Shaikh S. Haque<br/>
<br/>
View the full article
<br/>
File1:<br/>
<br/>
AC1-0002A,Jukebox,1149473,Marked Full,202,M,0,,0,0<br/>
AC1-0003A,Jukebox,1260463,Marked Not Full,204,M,0,,0,0<br/>
AC1-0003B,Jukebox,1258468,Marked Full,205,M,0,,0,0<br/>
AC1-0001A,Jukebox,1111111,Marked Not Full,201,M,0,,0,0<br/>
AC1-0004A,Jukebox,1258439,Marked Full,206,M,0,,0,0<br/>
AC1-0005A,Jukebox,221460,Marked Not Full,208,M,0,,0,0<br/>
AC1-0005B,Jukebox,546985,Marked Not Full,209,M,0,,0,0<br/>
AC1-0006A,Jukebox,1258468,Marked Not Full,211,M,0,,0,0<br/>
<br/>
<br/>
File2:<br/>
<br/>
AC1-0002A,Jukebox,1149473,Marked Full,202,M,0,,0,0<br/>
AC1-0003A,Jukebox,1262454,Marked Not Full,204,M,0,,0,0<br/>
AC1-0003B,Jukebox,1258468,Marked Full,205,M,0,,0,0<br/>
AC1-0004A,Jukebox,1258439,Marked Full,206,M,0,,0,0<br/>
AC1-0004B,Jukebox,221460,Marked Not Full,208,M,0,,0,0<br/>
AC1-0005B,Jukebox,547234,Marked Not Full,209,M,0,,0,0<br/>
AC1-0006A,Jukebox,1260231,Marked Not Full,211,M,0,,0,0<br/>
AC1-0006B,Jukebox,1258468,Marked Not Full,211,M,0,,0,0<br/>
<br/>
<br/>
Expected result:<br/>
<br/>
AC1-0003A,Jukebox,1260463,Marked Not Full,204,M,0,,0,0,AC1-0003A,Jukebox,1262454,Marked Not Full,204,M,0,,0,0<br/>
AC1-0001A,Jukebox,1111111,Marked Not Full,201,M,0,,0,0,,,,,,,,,,<br/>
AC1-0005A,Jukebox,221460,Marked Not Full,208,M,0,,0,0,,,,,,,,,,<br/>
AC1-0005B,Jukebox,546985,Marked Not Full,209,M,0,,0,0,AC1-0005B,Jukebox,547234,Marked Not Full,209,M,0,,0,0<br/>
AC1-0006A,Jukebox,1258468,Marked Not Full,211,M,0,,0,0,AC1-0006A,Jukebox,1260231,Marked Not Full,211,M,0,,0,0<br/>
,,,,,,,,,,AC1-0006B,Jukebox,1258468,Marked Not Full,211,M,0,,0,0<br/>
<br/>
<br/>
I have come up with follows, but not getting the expected result:<br/>
<br/>
strHeaderFile = "File1"<br/>
strOrderFile = "File2"<br/>
strOutputFile = "RESULT.TXT"<br/>
strContents = ""<br/>
Const intForReading = 1<br/>
Set objFSO = CreateObject("Scripting.FileSystemObject")<br/>
Set objHeaderFile = objFSO.OpenTextFile(strHeaderFile, intForReading, False)<br/>
While Not objHeaderFile.AtEndOfStream<br/>
strHeaderLine = objHeaderFile.ReadLine<br/>
strHeaderOrdNum = Split(strHeaderLine, ",")(0)<br/>
strVolStatN = Split(strHeaderLine, ",")(3)<br/>
Set objOrderFile = objFSO.OpenTextFile(strOrderFile, intForReading, False)<br/>
While Not objOrderFile.AtEndOfStream<br/>
strOrderLine = objOrderFile.ReadLine<br/>
strOrderOrdNum = Split(strOrderLine, ",")(0)<br/>
strVolStatO = Split(strOrderLine, ",")(3)
<br/>
<br/>
==============================================================<br/>
If strOrderOrdNum = strHeaderOrdNum and strVolStatN = "Marked Not Full" Then<br/>
<br/>
If strContents = strOrderLine Then<br/>
<br/>
strContents = ""<br/>
Else<br/>
strContents = strContents & VbCrLf & strOrderLine & "," & strHeaderLine<br/>
End If <br/>
<br/>
Else <br/>
<br/>
If strHeaderOrdNum <> strOrderOrdNum Then <br/>
If strContents <> null Then
<br/>
strContents = strContents & VbCrLf & strOrderLine & ",,,,,,,,,"
<br/>
else
<br/>
strContents = nothing<br/>
end if<br/>
End if<br/>
<br/>
End If<br/>
=======================================================================================
<br/>
<br/>
Wend<br/>
<br/>
<br/>
objOrderFile.Close<br/>
Set objOrderFile = Nothing<br/>
Wend<br/>
wscript.echo strContents <br/>
objHeaderFile.Close<br/>
Set objHeaderFile = Nothing<br/>
<br/>
Now output the final file<br/>
Set objOutputFile = objFSO.CreateTextFile(strOutputFile, True)<br/>
objOutputFile.Write strContents<br/>
objOutputFile.Close<br/>
Set objOutputFile = Nothing<br/>
Set objFSO = Nothing<br/>
<br/>
Please help me out.<br/>
Thanks<br/>
Shaikh S. Haque<br/>
<br/>
View the full article