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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extract text from a file

Status
Not open for further replies.

Matta25

Technical User
Jan 6, 2004
82
US
Is there a simple was to open a text file and search for a string, then from the start of that string read in 10 character to a varible. Or is there a way to search a string with wildcard character? (examlpe the string may have AK5~A or AK5*A or AK5-A, can I use a STRFIND command to find AK5?A ?=wildcard character)
Thanks
 
There is no way to perform a wildcard search in ASPECT. About the best you can do is read a file line by line and use the strfind command to search for the common portion of each string. Strfind supports an optional integer argument that lets you get the location in the string where the substring you searched for is located. You could then use the substr command to copy the 10 characters you needed starting with the location returned by the strfind command.


aspect@aspectscripting.com
 
Matta25 -- presumably you are reading in a 997? Since the ISA segment is of fixed length, and should contain the delimiter (the ~, *, - you referenced in your post), once you get the delimiter used from the ISA segment, you should be able to find the same delimiters in the AK5 segments.

(Try getting the value in byte position 104 of the file.)

hopefully that makes sense, but hopefully you've found your solution by now, too. hopefully you are reading a 'standard 997', also -- some do not always play by the rules.

 
Thank you for the help. You are correct, this is a 997 file. The problem is we get all type of 997. (I work for a clearing house.) I want to write some logic into all our script to open the 997 and see if it is accepted or not and put this in the filename of the zip file. This way it will save time having to open each 997 to look for AK5 segment.
Thanks again.
 
alternatively, you can look for AK3 or AK4 -- then you would know you had a rejected transaction.

Otherwise, here's a sample of some 'rudimentary' code I use on a daily basis. There may be an easier way, but I'm sorta new to Procomm. You'll have to tweak it for your use:

integer FileCounter = 0, Len = 0
string FileSpec, LineBuffer, sFullPath, sString, sFileRename, sLogFile, sWriteString

proc main
strcpy sLogFile s0
strcat sLogFile "\IN\logfile.txt"
if fopen 1 sLogFile CREATE TEXT
strcpy FileSpec s0
strcat FileSpec "\IN\mail*"

if findfirst FileSpec ; Find first file matching spec.
FileCounter++
strcpy sFullPath s0
strcat sFullPath "\IN\"
strcat sFullPath $FILENAME
strcpy sFileRename s0
strcat sFileRename "\IN\"

if fopen 0 sFullPath READ TEXT
fgets 0 LineBuffer
substr sString LineBuffer 1 2
if strfind LineBuffer "~ST*997"
strcat sFileRename "997."
call RenameFile
else
if strfind LineBuffer "~ST*835"
strcat sFileRename "835."
call RenameFile
else
if strcmp sString " H"
strcat sFileRename "ACK."
call RenameFile
else
fgets 0 LineBuffer
if strfind LineBuffer "submission id"
strcat sFileRename "TRANS."
call RenameFile
else
strcat sFileRename "NSF."
call RenameFile
endif
endif
endif
endif
endif
while findnext ; Loop while still finding files.
strcpy sFullPath s0
strcat sFullPath "\IN\"
strcat sFullPath $FILENAME
strcpy sFileRename s0
strcat sFileRename "\IN\"

if fopen 0 sFullPath READ TEXT
fgets 0 LineBuffer
substr sString LineBuffer 1 2
if strfind LineBuffer "~ST*997"
strcat sFileRename "997."
call RenameFile
else
if strfind LineBuffer "~ST*835"
strcat sFileRename "835."
call RenameFile
else
if strcmp sString " H"
strcat sFileRename "ACK."
call RenameFile
else
fgets 0 LineBuffer
if strfind LineBuffer "submission id"
strcat sFileRename "TRANS."
call RenameFile
else
strcat sFileRename "NSF."
call RenameFile
endif
endif
endif
endif
endif
FileCounter++
endwhile
endif
fclose 1
endif
pwexit
endproc

proc RenameFile
strcat sFileRename $FILENAME
strcat sFileRename ".txt"
fclose 0
rename sFullPath sFileRename
strcpy sWriteString sFullPath
strcat sWriteString " "
strcat sWriteString sFileRename
strlen sWriteString Len
fputs 1 sWriteString
endproc
 
Hi ElusiveCow,

Have you further refined this or would you be willing to further elaborate on your post here? I am trying to pull 835's off IndianaMedicaid's site and have other file type I need to be able to differentiate among (271's, 277's, 278's, 997's and 820's).

I am completely new to ProComm and EDI transactions. I do have 'rudimentary' programming skills though.

Thanks,
Bubarooni
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top