Question Exporting one column value from imput Text file

sreekuax

Member
Hello,
I am having an iput file which is a text file with pipe delimiter. Need to extract only 3rd column values from this input file to another file. Other than using variables to do the task, is there any other options.
Thanks for any help.
 

Cringer

ProgressTalk.com Moderator
Staff member
What Progress version? If you are on a modern enough version you can copy the whole file into a longchar and parse the data yourself without having to import it line by line.
 

Cringer

ProgressTalk.com Moderator
Staff member
So you use COPY-LOB FROM FILE <file> TO OBJECT mylongchar. Then the whole file contents will be in the variable and you can just use it like you would any character variable. Depending on your OS the file will have CHR(10) or CHR(13) or both at the end of each line so you can go through line by line and get entry(3) of the line.
 

sreekuax

Member
Hi Cringer ,

I tried somthing like this :

DEF VAR l-val AS CHAR NO-UNDO.
DEF VAR l-rslt AS CHAR NO-UNDO.

INPUT FROM VALUE("/home/data/Data_File.txt").
REPEAT:
IMPORT UNFORMATTED l-val.
display l-val format "x(60)".
display ENTRY(3,l-val).


***************************
But I am getting an error Entry 3 is outside the range of list. does that mean the whole data is considerd as one single entry ?
 

Cringer

ProgressTalk.com Moderator
Staff member
Well for starters you aren't listening to what I suggested. Secondly, you stated in your definition that your file is pipe delimited but your ENTRY() is using the default of comma. You need to do ENTRY(3,l-val,"|").
 

sreekuax

Member
Well for starters you aren't listening to what I suggested. Secondly, you stated in your definition that your file is pipe delimited but your ENTRY() is using the default of comma. You need to do ENTRY(3,l-val,"|").

Thanks for correcting me.

Trying like below :

DEF VAR l-val AS CHAR NO-UNDO.
DEF VAR mylongchar AS LONGCHAR NO-UNDO.
DEF VAR l-rslt AS CHAR NO-UNDO.
DEF VAR l-TEMP AS CHAR NO-UNDO.

INPUT FROM VALUE("/home/data/Data_File.txt").
REPEAT:
IMPORT UNFORMATTED l-val.
l-TEMP = l-val.
END.
INPUT CLOSE.

COPY-LOB FROM L-TEMP TO mylongchar.

l-rslt = ENTRY(3,mylongchar,"|").
DISPLAY l-rslt.

In this case am getting another error - COPY-LOB only works on large object fields. (11285)
please excuse if I am still doing something wrong . Expecting your advise on this.
 

TomBascom

Curmudgeon
As much as I love the 4gl... wouldn't it make more sense to use a purpose build OS utility? Like "cut"?

cut -d '|' -f 3 < test.txt

If you are going to use the 4GL then the obvious solution is something similar to:

Code:
define variable x as character no-undo.
input from value( "test.txt" ).
output to value( "result.txt" ).
repeat:
    import delimiter "|" ^ ^ x.
    put unformatted x skip.
end.
output close.
input close.
 

sreekuax

Member
As much as I love the 4gl... wouldn't it make more sense to use a purpose build OS utility? Like "cut"?

cut -d '|' -f 3 < test.txt

If you are going to use the 4GL then the obvious solution is something similar to:

Code:
define variable x as character no-undo.
input from value( "test.txt" ).
output to value( "result.txt" ).
repeat:
    import delimiter "|" ^ ^ x.
    put unformatted x skip.
end.
output close.
input close.


Now that is absolutely doing wonders for me.... Thanks alot Tom and Cringer for the help and mentoring :)
 
Top