What does the Text Diff Tool do?
The Text Diff Tool compares two text documents side-by-side or line-by-line, highlighting additions (green), deletions (red), and modified characters between original and updated versions. It calculates line-level additions and removals, computes similarity percentages, and allows ignoring leading/trailing whitespace variations or character case differences.
Core Concepts
Understanding line-by-line and character-level difference algorithms:
- Line-Level Difference Detection: Identifies exact line additions, removals, and unchanged anchor rows with line number tracking.
- Character Similarity Thresholding: Distinguishes between completely new lines and minor line modifications (typos, word adjustments) using character distance calculation.
- Normalization Filters: Supports toggling whitespace ignorance (ignoring leading/trailing padding) and case-insensitive comparison.
How to use the tool?
- Paste Text Payloads: Paste your baseline (original) text document into the left editor and your updated text document into the right editor or click Load Sample.
- Configure Comparison Rules:
- Check Ignore Leading/Trailing Whitespace Differences to ignore padding shifts.
- Check Ignore Case Differences to focus exclusively on textual changes.
- Execute & Inspect: Click Compare Text Documents to review highlighted line additions, deletions, modifications, and summary counts.
Related Developer Utilities
If you work with text comparisons, line formatting, and document manipulation, explore these complementary tools:
- YAML Diff Tool: Compare two YAML documents side-by-side with structural diff detection.
- JSON Diff Tool: Compare two JSON documents with deep object diff inspection.
- Trim Trailing Spaces Tool: Strip trailing spaces from source code lines.
- Remove Empty Lines Tool: Strip blank and whitespace-only lines from text files.
REST API Integration
Blueutils provides a free REST API endpoint (POST https://blueutils.com/api/text/diff) to programmatically compare two text documents line-by-line and character-by-character while highlighting additions, deletions, and line-level modifications.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
leftRaw |
String | Original left text document payload string. | "Line 1\nLine 2" |
rightRaw |
String | Modified right text document payload string. | "Line 1\nLine 2 (modified)" |
ignoreWhitespace |
Boolean | Ignore leading/trailing line whitespace differences. Defaults to false. |
false |
ignoreCase |
Boolean | Ignore character casing differences. Defaults to false. |
false |
API Request Payload Examples
cURL
curl -X POST https://blueutils.com/api/text/diff \
-H "Content-Type: application/json" \
-d '{
"leftRaw": "Line 1\nLine 2",
"rightRaw": "Line 1\nLine 2 (modified)",
"ignoreWhitespace": false
}'Python
import requests
url = "https://blueutils.com/api/text/diff"
payload = {
"leftRaw": "Line 1\nLine 2",
"rightRaw": "Line 1\nLine 2 (modified)"
}
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 = """
{
"leftRaw": "Line 1\\nLine 2",
"rightRaw": "Line 1\\nLine 2 (modified)"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/text/diff"))
.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 comparison succeeded. |
true |
isIdentical |
Boolean | Returns true if left and right texts are 100% identical. |
false |
summary |
Object | Summary detailing added, removed, and unchanged line counts. | {"addedLines":1} |
lineDiffs |
Array | Array of line difference change objects with type, value, and line numbers. |
[...] |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"isIdentical": false,
"summary": {
"totalLinesLeft": 2,
"totalLinesRight": 2,
"addedLines": 0,
"removedLines": 0,
"modifiedLines": 1,
"unchangedLines": 1
},
"lineDiffs": [
{
"type": "unchanged",
"value": "Line 1",
"leftLine": 1,
"rightLine": 1
},
{
"type": "modified",
"oldValue": "Line 2",
"newValue": "Line 2 (modified)",
"leftLine": 2,
"rightLine": 2
}
]
}Validation Failure Response (HTTP 400 Bad Request)
{
"isValid": false,
"error": "Both left and right text inputs are required and must be strings."
}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 compare text documents?
Integrating the Text Diff API into document review workflows, audit logging systems, or AI validation pipelines provides essential benefits:
- Rapid Script Validation: Verifies code or document changes programmatically before saving versions to cloud databases.
- Optimized Token Efficiency for AI Agents: LLMs struggle with character-level accuracy when comparing multi-paragraph text blocks. Calling the API returns deterministic diff arrays with zero token hallucination.
- Deterministic Accuracy Without Hallucinations: Ensures 100% accurate Myers diff calculations across thousands of document lines.
Native Usage
How to compare text documents locally in terminal environments or scripts:
Windows (CMD / PowerShell)
# Compare two text files in PowerShell
Compare-Object (Get-Content file1.txt) (Get-Content file2.txt)Linux / Unix (Bash)
# Using unified diff in Linux
diff -u file1.txt file2.txtPython
Using Python difflib:
import difflib
with open("file1.txt") as f1, open("file2.txt") as f2:
lines1 = f1.readlines()
lines2 = f2.readlines()
diff = difflib.unified_diff(lines1, lines2, fromfile="file1.txt", tofile="file2.txt")
print("".join(diff))Java
Using Java java.nio.file.Files:
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
public class TextDiffExample {
public static void main(String[] args) throws Exception {
List<String> f1 = Files.readAllLines(Paths.get("file1.txt"));
List<String> f2 = Files.readAllLines(Paths.get("file2.txt"));
System.out.println("Files match: " + f1.equals(f2));
}
}