File Conversion: UNIX.txt to DOS.txt and trim trailing blanks 
Author Message
 File Conversion: UNIX.txt to DOS.txt and trim trailing blanks

On a weekly basis we report that is created in an UNIX.txt format.
This file needs to be converted as follows:
    1.   from UNIX.txt to DOS.txt
    2.   trailing blank spaces removed.

How could this file be converted (using Clarion code) into a DOS.txt format
and the blank spaces removed.
Info:
The difference between the 2 types of txt.formats is: in the DOS.txt format
the rows of data are ended by a CR/LF.

For the conversion from UNIX.txt to DOS.txt 3 scenarios need
to be addressed:
1.    IF a CR is found without a LF, a LineFeed is added
2.    IF a LF is found without a CR, a CarriageReturn is inserted before it
3.    IF the signs are switched around (LF/CR), the signs are ordered
correctly as CR/LF.

Then the trailing blank spaces from the specified value needs to be removed:
For example "some text           "   ==>>   "some text".

Once this is done, the data is correctly formated and can be used.

Would you be able to help me in this matter ?
TIA and kind regards
Karlo



Wed, 14 Jan 2004 01:26:22 GMT  
 File Conversion: UNIX.txt to DOS.txt and trim trailing blanks
Hello, Karlo.

I suggest using two files; one to read from the UNIX file and one to write
to the DOS file.

To read from the UNIX file, use a declaration similar to the following:

inUNIX            file,driver('ASCII',
'/ENDOFRECORD=1,10'),pre(inUNIX),name(...)
record                record,pre()
line                      string(200)    ! or whatever is needed.
                      end
                  end
<<<

To write to the DOS file, use a declaration similar to the following:

outDOS            file,driver('ASCII',
'/ENDOFRECORD=2,13,10'),pre(outDOS),name(...)
record                record,pre()
line                      string(200)    ! or whatever is needed.
                      end
                  end
<<<

The idea is to loop through all the lines in the UNIX file and send them to
the DOS file.  Here is a snippet of code:

set(inUNIX)
loop
    next(inUNIX)
    if errorcode() = 33
        break
    if errorcode() > 0
        ! Handle errors.
    end
    outDOS.line = clip(inUNIX.line)        ! Strips trailing spaces.
    append(outDOS)
    if errorcode() > 0
        ! Handle errors.
    end
end
<<<

As for addressing all permutations of CR and LF, I say don't bother!  If the
source of your UNIX file cannot generate a properly formatted file, then
that is their problem.

                            -Ray.


Quote:
> On a weekly basis we report that is created in an UNIX.txt format.
> This file needs to be converted as follows:
>     1.   from UNIX.txt to DOS.txt
>     2.   trailing blank spaces removed.

> How could this file be converted (using Clarion code) into a DOS.txt
format
> and the blank spaces removed.
> Info:
> The difference between the 2 types of txt.formats is: in the DOS.txt
format
> the rows of data are ended by a CR/LF.

> For the conversion from UNIX.txt to DOS.txt 3 scenarios need
> to be addressed:
> 1.    IF a CR is found without a LF, a LineFeed is added
> 2.    IF a LF is found without a CR, a CarriageReturn is inserted before
it
> 3.    IF the signs are switched around (LF/CR), the signs are ordered
> correctly as CR/LF.

> Then the trailing blank spaces from the specified value needs to be
removed:
> For example "some text           "   ==>>   "some text".

> Once this is done, the data is correctly formated and can be used.

> Would you be able to help me in this matter ?
> TIA and kind regards
> Karlo



Wed, 14 Jan 2004 02:24:30 GMT  
 File Conversion: UNIX.txt to DOS.txt and trim trailing blanks
The Unix command 'doscp' will take care of the cr/lf problem for you. So all
that is left is the clipping of the fields, easily handled by the clip
function in Clarion.
The syntax for the doscp is as follows:

            doscp filename a:        in most SCO Unix or Caldera Unix
     this will copy file 'filename' to a diskette.
            remember that case is important in Unix. (a is not equal to A ).

Ygnacio Moreno

Quote:

>On a weekly basis we report that is created in an UNIX.txt format.
>This file needs to be converted as follows:
>    1.   from UNIX.txt to DOS.txt
>    2.   trailing blank spaces removed.



Wed, 14 Jan 2004 04:27:04 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. if file1.txt < file2.txt echo smaller

2. Display Dos .txt file

3. Attaching TXT files to a file

4. Copy a *.txt file to another file

5. translante cobol files to txt of mdb files

6. clipper for Unix - flagship.txt (0/1)

7. clipper for Unix - flagship.txt (1/1)

8. Client-Server between WinNT and UNIX - assina~1.txt (0/1)

9. Client-Server between WinNT and UNIX - assina~1.txt (1/1)

10. Filter thr txt file and eliminate unwanted columns

11. nawk: hosts.txt makes too many open files

12. read a particular line from txt file

 

 
Powered by phpBB® Forum Software