Documents

Text Diff

Try it

Show line-by-line differences between two text files using Python's difflib. Supports unified, context, and side-by-side comparison modes with configurable c...

What it does

Show line-by-line differences between two text files using Python's difflib. Supports unified, context, and side-by-side comparison modes with configurable context lines.

The skill document

text-diff

Show line-by-line differences between two text files using Python's difflib.

Usage Scenarios

Scenario 1: Compare Configuration File Versions

User input: "比较两个版本的配置文件有什么不同。"

Expected output: Unified diff output showing added lines with +, removed lines with -, and context around changes for old_config.ini vs new_config.ini.

Scenario 2: Side-by-Side Comparison

User input: "帮我并排对比这两份文案的差异。"

Expected output: Side-by-side layout with original on left, revised on right, differences highlighted. Changed lines shown aligned with their counterparts.

Scenario 3: Check if Files Are Identical

User input: "检查这两个文件是不是完全一样。"

Expected output: Exit code 0 with message "Files are identical" if no differences found, or exit code 1 with detailed diff output showing all changes if files differ.

Scenario 4: 合同版本对比

User input: "我把租房合同改了几个地方发给中介了,他怎么改的我没看出来,帮我对比一下两版合同的区别。" Expected output: 对原始版和修改版进行逐行差异对比(diff),高亮增删改的部分。用颜色标注:红色删除、绿色新增、黄色修改。支持word/PDF/markdown格式。输出差异摘要:几处新增、几处删除、几处修改。针对合同中的关键条款(租金、违约责任、租期等)的变更做特别标注。

Description

A utility skill for comparing two text files and displaying their differences in a readable format. Supports unified diff output and side-by-side comparison modes.

Usage

# Show unified diff between two files
python ~/.openclaw/skills/text-diff/text_diff.py unified file1.txt file2.txt

# Show side-by-side comparison
python ~/.openclaw/skills/text-diff/text_diff.py side-by-side file1.txt file2.txt

# Show context diff (3 lines of context)
python ~/.openclaw/skills/text-diff/text_diff.py context file1.txt file2.txt

# Compare with custom context lines
python ~/.openclaw/skills/text-diff/text_diff.py unified file1.txt file2.txt -c 5

Options

  • unified: Show unified diff format (default)
  • context: Show context diff format
  • side-by-side: Show line-by-line comparison
  • -c, --context: Number of context lines (default: 3)
  • -o, --output: Save diff to file instead of stdout
  • --no-color: Disable colored output

Examples

# Basic unified diff
python ~/.openclaw/skills/text-diff/text_diff.py unified old.txt new.txt

# Side-by-side comparison with no colors (for piping)
python ~/.openclaw/skills/text-diff/text_diff.py side-by-side old.txt new.txt --no-color

# Save diff to file
python ~/.openclaw/skills/text-diff/text_diff.py unified old.txt new.txt -o diff.txt

# Compare with 10 lines of context
python ~/.openclaw/skills/text-diff/text_diff.py context old.txt new.txt -c 10

Output Format

Unified Diff

--- old.txt
+++ new.txt
@@ -1,5 +1,5 @@
 line 1
 line 2
-line 3 (removed)
+line 3 (added)
 line 4
 line 5

Side-by-Side

OLD                          | NEW
---------------------------- | ----------------------------
line 1                       | line 1
line 2                       | line 2
line 3 (removed)             | line 3 (added)
line 4                       | line 4

Exit Codes

  • 0: Files are identical
  • 1: Files differ
  • `

Related skills

Smart text comparison tool with format-aware diffing, AI explanation, and 3-way merge. Covers structured JSON, YAML, CSV, code, and plain text.

4 installs

Generate HTML code review pages with risk tags, diff highlights, and file-level annotations. 当用户需要代码审查可视化、PR审查报告、代码diff高亮、风险标签标注、审查页面生成时使用。

3 installs

Compute SHA-256 or MD5 hashes of text strings. Useful for quick integrity checks, deduplication, and content fingerprinting without leaving the terminal.

2 installs

Validate, format, query, diff, filter, flatten, merge JSON files with dot-notation paths

1 installs

Compare two versions of a .docx document and produce a single Word file in tracked-changes (revision / tracking) mode, as if a human had edited the old file into the new one with Track Changes turned on. Use whenever the user has two versions of a DOCX (e.g., successive drafts of a paper, report, or contract — often AI-generated or AI-assisted revisions) and wants to see the differences as native Word revisions (insertions/deletions) that can be accepted/rejected in Word. Triggers: "对比两个版本的 docx", "tracked changes", "tracking mode", "修订模式对比", "compare two Word documents", "diff two drafts", "生成修订对比文件". Do NOT use for: creating new documents from scratch (use docx skill), single-file editing with revisions (use docx WIR engine), or PDF-only comparisons.

Text processing toolkit - format, clean, convert, analyze text. Includes markdown formatting, text cleaning, word count, case conversion, find/replace, text...

4 installs