cktb -- Check for trailing blanks (spaces, tabs) in a file


cktb.pl is a Perl program which checks for trailing blanks (space or tabs) in a text file and reports the number found and the longest string of blanks found. This is useful for data prep, scripting, and version control where you want clean copies of files.

This program was written because one place I worked didn't want any programs with spaces or tabs at the end of any line. So this program checks for that issue. It's easier to get a report where this issue is found than trying do it in your editor (although some editors can get find spaces at the end of the lines, like vim). If you can do that, more power to you. And if anyone thinks they've gotten rid of them you can show them a report from this program.

Yes, it's a relatively simple program but you would not believe the number of times it proved that even though people did their best to get rid of trailing white space in their programs, there was still some there. A program like this makes all the difference in proving it. If you're a programmer, that's something worth writing a program for! And others can use it to check their programs for trailing white space.

Limitations:

Usage

cktb.pl [-l] filename [filename...] where: -l gives long output, instead of a summary.

For example, here is a file with some trailing white space and what the report will show. I've marked the end of the lines with the vertical bars ("|") so you can see there is some white space of varying lengths on a few of the lines.

This utility is part of a collection of more text-processing tools.

Input (9 lines):

A line with no trailing blanks.|

A line with one trailing blank. |

A line with several trailing blanks   |

A line with a lot of trailing blanks                      |

Output (default):
~> cktb.pl cktbtest.in
 Page 1

    cktb.pl: Find lines with trailing spaces or tabs, by Kent Nassen, v1.2, 9/20/25
    Scanning for trailing white space in the file: cktbtest.in
    Report generated: Sat Sep 20 21:15:36 2025


    9 total lines in the file 'cktbtest.in'.
    Longest string of trailing whitespace was 22 characters at line 8.

 ------------------------------------------------------------------------

Output (using -l option):
 cktb.pl -l cktbtest.in
  
  Page 1

   cktb.pl: Find lines with trailing spaces or tabs, by Kent Nassen, v1.2, 9/20/25
   Scanning for trailing white space in the file: cktbtest.in
   Report generated: Sat Sep 20 21:22:39 2025

               Trailing WS
     Line #       Length
     -------   -----------
           4          1
           6          3
           8         22

   9 total lines in the file 'cktbtest.in'.
   Longest string of trailing whitespace was 22 characters at line 8.

------------------------------------------------------------------------

Back to Kent's Perl Page Last-modified: Sat Sep 20 23:33:47 EDT 2025