Add Line Numbers to Text

Prepend customizable line numbers, prefixes, zero-padding, and custom delimiters to raw text lists, code blocks, and log files.

How to Add Line Numbers to Text Online

1

Paste Unnumbered Text

Enter your unnumbered text payload or script lists into the editor above or click Upload.

2

Choose Options

Configure start index offsets, line increments, delimiters (., :, or brackets), and zero padding.

3

Copy Result

The numbered text generates automatically in real time. Click Copy to export the result.

Tool Options

Custom Line Indexing & Step

Defines custom starting numbers (e.g., beginning at 0 or 100) and custom positive integer increments.

Formatting Delimiters & Padding

Decorate numbers using periods (1.), colons (1:), brackets ([1]), or pad leading indices with zeroes (001).

Smart Empty Line Handling

Configure options to skip empty lines, preventing number sequence incrementing on empty paragraph spaces.

Your Data Privacy

Web Tool
Privacy-First Architecture
Most of our web tools process your data entirely in-browser. Where server processing is technically required, payloads are evaluated statelessly in-memory and are never stored, saved, or logged.
REST API
Stateless In-Memory Processing
When you use our API endpoints, your requests are processed strictly in-memory without persistent database storage, disk logging, or data retention.
Want to learn more about how we safeguard your information and infrastructure?
Read our full Privacy Policy for detailed security standards, data retention principles, and compliance guarantees.

What does the Add Line Numbers to Text do?

The Add Line Numbers to Text Tool prepends customizable row numbers, configurable start index offsets, step increments, leading zero-padding (e.g. 001, 002), and formatting delimiters (., :, [], )) to every line of a text document or log file.

Core Concepts

Understanding line numbering configurations and alignment rules:

  • Index Offsets & Step Increments: Set custom initial indices (e.g. starting at 0 or 100) and custom step increments (e.g. counting by 5s or 10s).
  • Zero Padding Width: Dynamically computes the maximum digit width based on total line count to ensure uniform alignment across lines (01., 02., ... 99.).
  • Empty Line Skipping: Optionally bypasses empty or blank lines so that paragraph breaks do not increment the line counter.

How to use the tool?

  1. Paste Raw Text: Enter your unnumbered text payload into the editor or click Load Sample.
  2. Configure Options:
    • Set the Start At integer and Increment step.
    • Choose a Delimiter format (Period, Colon, Parenthesis, Brackets, Space).
    • Toggle Zero Padding or Skip Empty Lines.
  3. Execute & Export: Click Add Line Numbers, then click Copy or Download to save your numbered text.

Related Developer Utilities

If you work with text formatting, list processing, and document manipulation, explore these complementary tools:

REST API Integration

Blueutils provides a free REST API endpoint (POST https://blueutils.com/api/text/add-line-numbers) to programmatically prepend customizable line numbers, zero-padding, prefixes, and delimiters to raw text payloads.

API Request Parameters

Name Type Description Example
rawText String Raw multiline text payload string to add line numbers to. "Line A\nLine B"
startNumber Number Starting integer for line numbering. Defaults to 1. 1
increment Number Step increment value for line numbers. Defaults to 1. 1
delimiterStyle String Delimiter style ("period", "colon", "parenthesis", "brackets", "space"). Defaults to "period". "period"
padZeroes Boolean Apply leading zero padding based on max line count. Defaults to false. false
skipEmptyLines Boolean Skip numbering blank or empty lines. Defaults to false. false

API Request Payload Examples

cURL

curl -X POST https://blueutils.com/api/text/add-line-numbers \
  -H "Content-Type: application/json" \
  -d '{
    "rawText": "Initialize Blueutils\nMount routers\nStart server",
    "startNumber": 1,
    "increment": 1,
    "delimiterStyle": "period",
    "padZeroes": true
  }'

Python

import requests

url = "https://blueutils.com/api/text/add-line-numbers"
payload = {
    "rawText": "Initialize Blueutils\nMount routers\nStart server",
    "startNumber": 1,
    "delimiterStyle": "period",
    "padZeroes": True
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())

Java

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        String jsonPayload = """
            {
                "rawText": "Initialize Blueutils\\nMount routers\\nStart server",
                "startNumber": 1,
                "delimiterStyle": "period",
                "padZeroes": true
            }
            """;

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://blueutils.com/api/text/add-line-numbers"))
            .header("Content-Type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}

API Response Parameters

Name Type Description Example
isValid Boolean Returns true if line numbers were successfully prepended. true
result String Formatted text string containing prepended line numbers. "01. Initialize Blueutils\n02. Mount routers\n03. Start server"
lineCount Number Total count of lines processed. 3
numberedLineCount Number Count of lines that received line numbers. 3

API Response Payload Examples

Success Response (HTTP 200 OK)

{
  "isValid": true,
  "result": "01. Initialize Blueutils\n02. Mount routers\n03. Start server",
  "lineCount": 3,
  "numberedLineCount": 3
}

Validation Failure Response (HTTP 400 Bad Request)

{
  "isValid": false,
  "error": "Input text payload cannot be empty."
}

Rate Limit Exceeded Response (HTTP 429 Too Many Requests)

{
  "error": "API rate limit exceeded. Please wait or contact support@blueutils.com."
}

Why use an API to add line numbers?

Integrating the Add Line Numbers API into code review automation bots, document export pipelines, or AI agent tool calling provides key benefits:

  • Rapid Script Validation: Prepares indexed code snippets and log traces before publishing to ticketing systems or chat webhooks.
  • Optimized Token Efficiency for AI Agents: LLMs often skip or miscount indices when asked to number long lists. Calling the API returns deterministic sequential numbers without burning completion tokens.
  • Deterministic Accuracy Without Hallucinations: Ensures 100% accurate zero-padding calculations and delimiter placement across thousands of lines.

Native Usage

How to prepend line numbers to text files locally in terminal environments or scripts:

Windows (CMD / PowerShell)

# Prepend line numbers in PowerShell
$i = 1; Get-Content input.txt | ForEach-Object { "$i. $_"; $i++ } | Set-Content numbered.txt

Linux / Unix (Bash)

# Using nl or cat -n in Linux
nl -b a -s ". " input.txt > numbered.txt

Python

Using Python enumerate:

with open("input.txt") as f:
    lines = f.readlines()

numbered = [f"{i + 1}. {line}" for i, line in enumerate(lines)]
with open("numbered.txt", "w") as f:
    f.writelines(numbered)

print("Numbered lines saved.")

Java

Using Java Streams and AtomicInteger:

import java.nio.file.*;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

public class AddLineNumbersExample {
    public static void main(String[] args) throws Exception {
        List<String> lines = Files.readAllLines(Paths.get("input.txt"));
        AtomicInteger idx = new AtomicInteger(1);

        List<String> numbered = lines.stream()
            .map(line -> idx.getAndIncrement() + ". " + line)
            .collect(Collectors.toList());

        Files.write(Paths.get("numbered.txt"), numbered);
        System.out.println("Numbered lines saved.");
    }
}

Frequently Asked Questions (FAQ)

How do I add line numbers to text online?

Paste your text list into the editor. The tool automatically numbers each line. You can configure the starting number, step increment, and delimiter styles like periods or colons in the toolbar.

Can I skip empty lines when adding numbers?

Yes. Checking Skip Empty Lines forces the numbering engine to ignore blank carriage returns, keeping the sequence mapped only to lines containing actual text.

What is zero-padding?

Zero-padding adds leading zeroes so all line prefixes share the exact same width based on the total line count (e.g., generating 001, 002 through 100 instead of 1 and 100).

Can I customize the number formatting delimiter?

Yes. The toolbar allows you to choose between several delimiter suffixes, including a period (1.), colon (1:), parenthesis (1)), square brackets ([1]), or a raw space.

Is my text payload sent to any servers?

No. The line numbering parser executes 100% client-side directly within your browser memory. We never transmit or store your files.

Rate Limits

UI Limits
100 uses per 15 minutes
Max payload size: 5 MB
API Limits
5 requests per 60 minutes
Max payload size: 256 KB
Need higher API rate limits, increased payload sizes, or custom developer solutions?
Contact our engineering team at support@blueutils.com for custom rate limit increases, higher quota allocations, or tailored enterprise integrations.