PRB: How to Remove ^M (CHR(13)) from FoxPro UNIX Text File

ID: Q142285

2.60 UNIX kbinterop kbprb

The information in this article applies to:

SYMPTOMS

Foxpro for UNIX places a carriage return/line feed pair ( 0D 0A in hex ) at the end of lines in text files that were created by commands such as REPORT FORM xxxx TO FILE yyyy in addition to any printer codes that might be appropriate (if _PDSETUP contains a valid printer driver name).

Not all UNIX programs are designed to accommodate the carriage return character.

CAUSE

Foxpro expects the carriage return/line feed pair to be a proper line termination indicator and thus places it at the end of lines in text files it creates.

WORKAROUND

A program, such as the example below, may be used to read the text file after it is created by Foxpro and then output a new file, devoid of the ^M (CHR(13)) terminator for use by other UNIX programs.

* begin strip13.prg * Created to strip the ^M's (chr(13)) out of .TXT files that are * routinely added by Foxpro at the end of each line. PARAMETER out_fname IF .NOT. FILE(out_fname)

    WAIT WINDOW 'INPUT FILE ' + out_fname + ' does not exist'
ELSE
    in_fname='input.txt'        && name to change original file to
    IF FILE(in_fname)            && during the 'stripping' process
        DELETE FILE &in_fname
    ENDIF

    RENAME &out_fname TO &in_fname
    in_fh = FOPEN(in_fname)        && Input File Handle
    ifp_size=FSEEK(in_fh,0,2)
    ifp_top=FSEEK(in_fh,0)
    IF ifp_size <= 0
        WAIT WINDOW 'Your INPUT File Is Empty!!'
    ELSE
        IF FILE(out_fname)
            DELETE FILE out_fname    && just in case
        ENDIF
        out_fh=FCREATE(out_fname)    && Output File Handle
        DO WHILE .NOT. FEOF(in_fh)
            in_text = FGETS(in_fh)
            IF LEN(in_text)>0        && If blank line, don't write
                =FWRITE(out_fh,in_text+CHR(10))
            ENDIF
        ENDDO
    ENDIF
    =FCLOSE(in_fh)
    =FCLOSE(out_fh)
ENDIF * End of Strip13.prg

STATUS

This behavior is by design. FoxPro expects the carriage return/line feed pair to be a proper line termination indicator and thus places it at the end of lines in text files it creates.

MORE INFORMATION

Steps to Reproduce Behavior

1. Create a simple REPORT FORM using a simple data table.

2. Run the report using this syntax:

   _PDSETUP=""
   REPORT FORM <name> to file Test.txt

3. Examine the file Test.txt using the UNIX vi editor. You will notice what
   appears to be a control-m at the beginning of each line after the first
   line.

Additional reference words: 2.60 FoxUnix KBCategory: kbinterop kbprb KBSubcategory: FxinteropGeneral
Keywords          : FxinteropGeneral 
Version           : 2.60
Platform          : UNIX

Last Reviewed: January 16, 1996