What is a line counter?
A line counter tells you how many lines a piece of text contains and what those lines look like. It is handy whenever one line means one thing: rows in a CSV export, URLs in a redirect list, keywords in an SEO brief, entries in a robots.txt file or lines in a code snippet you are about to paste into functions.php.
Beyond the total, the tool separates non-empty and blank lines (a line with only spaces or tabs counts as blank), counts unique and duplicate lines, and finds the longest and shortest lines with their line numbers — useful for spotting an over-long title in a list or a line that breaks a fixed-width format.
The right-hand panel produces a copy of your text with line numbers, so you can reference "line 12" in a code review, a support ticket or documentation. Numbers can start anywhere, be padded with spaces or zeros, and use the separator you prefer.
How to use the Line Counter
- Paste your text or code into the input box, or click Sample to load a short PHP snippet.
- Read the counts: total, non-empty, blank, unique and duplicate lines, plus longest and shortest line.
- Choose a start number, padding and separator for the numbered version, and whether blank lines get a number.
- Copy the numbered text or download it as a
.txtfile.
Example
Three lines numbered from 1 with a period separator and space padding (ten or more lines get aligned numbers):
1. User-agent: *
2. Disallow: /wp-admin/
3. Allow: /wp-admin/admin-ajax.phpCommon uses
- Check a list of URLs or keywords has the expected number of entries before importing it.
- Find duplicate lines quickly, then remove them with the Duplicate Line Remover.
- Spot lines that are too long for a fixed-width field, an SMS or a meta title.
- Add line numbers to a code snippet for a tutorial, review comment or WordPress functions.php snippet.
- Count rows in CSV data before converting it with CSV to JSON.
Frequently Asked Questions
Does a trailing line break count as an extra line?
No. Text that ends with a line break — as most files do — is counted the way wc -l and code editors' status bars count it, so "a↵b↵" is two lines. A blank line in the middle of the text is always counted.
Which line endings are supported?
Unix (LF), Windows (CRLF) and classic Mac (CR) line endings are all recognized, even mixed in one text. To convert them, use the Text Cleaner.
How are line lengths measured?
In visible characters, so an emoji or an accented letter counts as one and a tab counts as one. The longest line ignores nothing; the shortest line ignores blank lines, which would otherwise always win.
Are duplicate lines compared case-sensitively?
Yes — the counter reports exact repeats. For case-insensitive or whitespace-tolerant comparison, use the options in the Duplicate Line Remover.
Can I sort the lines as well?
Use Sort Lines to order lines alphabetically, naturally, by length or by number, then come back to number them.