Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Quick way to find number of lines in 16GB file
Message
De
09/06/2020 17:50:37
 
 
Information générale
Forum:
Windows
Catégorie:
Informatique en général
Divers
Thread ID:
01674670
Message ID:
01674799
Vues:
45
>Hi everybody,
>
>I have a 16GB csv file. I'd like to find number of lines in that file, so I try wc -l "name of the file" command by opening GitBash in the directory containing that file. Unfortunately, I waited ~30+ minutes and didn't get any result it. Do you know a quick way of finding number of lines in such a huge file?
>
>I can open this file to view using Lister.exe but it doesn't give me the lines count. All other editors cannot open the file.
>
>Thanks in advance.
count_lines("c:\myfile.csv")


FUNCTION count_lines
LPARAMETERS tcFilename
LOCAL lnHandle, lnLines, lcData

    * Validate parameter
    IF TYPE("tcFilename") != "C" OR NOT FILE(tcFilename)
        MESSAGEBOX("Usage:  lines filename.ext", 0 + 64, "Count Lines")
        CANCEL
    ENDIF

    * Open the file
    lnHandle = FOPEN(tcFilename, 10)
    IF lnHandle <= 0
        MESSAGEBOX("Error opening " + tcFilename, 0 + 64, "Count Lines")
        CANCEL
    ENDIF

    * Count the lines
    lnLines = 0
    DO WHILE NOT FEOF(lnHandle)
        lcData  = FREAD(lnHandle, 65535)
        lnLines = lnLines + OCCURS(CHR(13), lcData)
    ENDDO
    FCLOSE(lnHandle)

    * Report
    MESSAGEBOX("File contains " + LTRIM(TRANSFORM(lnLines, "999,999,999")) + " lines.", 0 + 64, "Count Lines")
You may need to load the file into a hex editor and see what the end-of-line characters are. Some systems use CHR(13), some use CHR(10), some use CHR(13)+CHR(10), some use CHR(10)+CHR(13). Windows typically uses either CHR(13) or CHR(13) + CHR(10), so by counting only CHR(13) instances, you will accommodate both. But, it can still be off if the line-ending form is non-standard.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform