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?
- Paste Raw Text: Enter your unnumbered text payload into the editor or click Load Sample.
- 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.
- 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:
- Text Sorter Tool: Sort text lists alphabetically, numerically, or in reverse.
- Remove Empty Lines Tool: Strip blank and whitespace-only lines from text files.
- Word & Character Counter: Analyze text metrics, character counts, and word frequency.
- Text Case Converter: Convert raw text strings across UPPERCASE, camelCase, and snake_case.
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.txtLinux / Unix (Bash)
# Using nl or cat -n in Linux
nl -b a -s ". " input.txt > numbered.txtPython
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.");
}
}