I have a script that I'm working on where I need to find a line, write that line to a file and then get the following line and append it to the same line. If the first string of the line has a K in it, look for the following line.

The file layout is in the attached file.

The end result is a line that looks like this:
ABCD123 * DOE,JOHN J (61) 05/17/11 05/17/11 06/03/11 08/05/11 63 81.38 20.70 60.68 0.00 25.44

Here's the code I have so far:
 Code:
;Script Options
;$SO=SETOPTION("Explicit", "ON")
;$SO=SETOPTION("NoMacrosInStrings", "ON")
;$SO=SETOPTION("NoVarsInStrings", "ON")
BREAK ON
CLS

$file = "C:\temp\file.txt"
$handle = FreeFileHandle()

$sitearray = loadfile($file,"@crlf")

	For Each $line In $sitearray
	;	$line
		
		$field = Split($line," ")
		$field[0] ?
		If InSTR($field[0],"K")
			$field[0]

			Else
			"No K in string" ?
		EndIf
		
		Next


		
		
;Functionction	LoadFile()
;
;Author		Bryce Lindsay Bryce@isorg.net
;
;Action		Loads a file in to a variable or an array.
;
;Syntax		LoadFile("Filename",[Array Delim], [UNI/ANSI file type])
;
;Version	1.1
;
;Date Revised	9:14 AM 8/15/2006
;
;Parameters	Filename
;		name of the file that you want to load.
;
;		Optional Array
;		set this option if you want to return the 
;		information as an array split on the given value
;
;		Unicode/ANSI file type
;		3 = force file open as ANSI
;		2 = forse file open as UNI
;		1 = Opens the file using the system default. (the UDF will use this as default)
;
;Remarks		finaly made this into a UDF and posted it... got tired 
;		of having to hunt it down.
;
;Returns		if the array flag is not set it returns a variable 
;		containing the contents of the file.
;
;		if the array flag is set, it will return an array 
;		of the file split on the value of the given variable
;
;Dependencies	Scripting.FileSystemObject
;
;KiXtart Ver	4.51
; 
;Example(s)	
;		;load the file test.txt into a variable
;		$Data=loadfile('test.txt')
;		? $data 
;
;		;load the file "test.txt" into an array split on @crlf
;		$data = loadfile('test.txt',@crlf)
;		for each $line in $data
;			? $line
;		next
;*/
Function loadfile($file, optional $array, $Uni)
	DIM $fso,$f,$fs
	if $uni $uni = $uni-3 else $uni = -2 endif

	if not $uni $uni = -2 endif
	$fso = CreateObject("Scripting.FileSystemObject")
	$f = $fso.GetFile($file)
	If @ERROR Exit 2 EndIf
	$fs = $f.OpenAsTextStream(1,$uni)
	if not $array
		$loadfile = $fs.Read($f.size)
	else
		$loadfile = Split($fs.Read($f.size),$array)
	endif
	Exit @ERROR 
EndFunction




I'm stuck at how to get the line following the K line and append lines 1 and 2 (for lack of a better term) together. Any help is appreciated.


Attachments
Document2.txt (122 downloads)
Description: