Special characters for IMPORT statement?

D.Cook

Member
The documentation lists hyphen (-), period (.) and null character as having a special effect in an import file.
I'm wondering if there's others, and more specifically if there's a way to make a line get ignored (ie comment line)?
 

GregTomkins

Active Member
I have used IMPORT about a trillion times and I don't know about '-' and '.'; however, I do know about ^, which you can use to ignore a line. So if you say have a file and you know the first record is some header data you can do this:

Code:
IMPORT ^.
REPEAT:
  IMPORT real_data_goes_here.

There is no way I know of to do this from within the file itself, though, which I think is more what you meant. Presumably if you knew to put a special 'ignore me' character in the file, you would know to just not write it there in the first place?

Also, utilities like sed/awk are often your friend for this kind of thing.
 

tamhas

ProgressTalk.com Sponsor
Also, import unformatted which allows you to parse the line under programatic control.
 

Tarby777

Member
You can also use ^ to ignore any unwanted leading entries on a line:

Code:
IMPORT ^ ^ ^ fourthEntryOnTheLine.

I have used IMPORT about a trillion times and I don't know about '-' and '.'; however, I do know about ^, which you can use to ignore a line. So if you say have a file and you know the first record is some header data you can do this:

Code:
IMPORT ^.
REPEAT:
  IMPORT real_data_goes_here.

There is no way I know of to do this from within the file itself, though, which I think is more what you meant. Presumably if you knew to put a special 'ignore me' character in the file, you would know to just not write it there in the first place?

Also, utilities like sed/awk are often your friend for this kind of thing.
 

D.Cook

Member
Thanks guys.

^ is good, but only if the program knows it wants to ignore the line. I'd like to be able ignore any line that begins with a special character, which may not necessarily be the first line.

IMPORT UNFORMATTED will allow me to parse the input and decide whether or not it is a comment. But I'll lose the advantages of the IMPORT statement in parsing the input fields and placing them into the database records.

I had also considered reading in the line, then checking if the first field begins with a special character. But the issue is the AVM parses the input line first, generating errors if the line doesn't conform to the expected format.

I think I'll just have to have files with no comments!
 

Tarby777

Member
Hmm... maybe a first pass through the file, allowing you to store the line numbers you want to ignore on the second pass?

Or having two copies of the (same) file, with an input stream open on each of them, reading them in at the same time and doing your processing only on "file 2", based on what you find in "file 1"?

Or reading the file into a temp-table and deleting the records you don't want (before optionally writing the TT out to a new file)?

I also seem to remember a "seek input to" command in the dim and distant P4GL past, allowing you - IIRC - to position the input cursor to a certain point in a file. Not saying it would be appropriate here, but it might be worth checking out...

Personally, I reckon an OS utility to fix up the file is the way to go... as has been said, grep/sed/awk are great for this kind of thing, although if you want to do it programatically, you could read in the file and write out only the "good" lines to a new file...
 
Top