text-tools

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Text Tools Skill

文本处理工具Skill

Text processing utilities for common operations.
用于常见操作的文本处理工具集。

When to Use

使用场景

USE this skill when:
  • "Count words in this text"
  • "Convert text to uppercase/lowercase"
  • "Remove duplicate lines"
  • "Sort lines alphabetically"
  • "Find and replace text"
当你有以下需求时使用本Skill:
  • "统计这段文本的字数"
  • "将文本转换为大写/小写"
  • "移除重复行"
  • "按字母顺序排序行"
  • "查找并替换文本"

When NOT to Use

不适用场景

DON'T use this skill when:
  • Complex regex operations → use sed/awk directly
  • File encoding conversion → use iconv
  • Binary file processing → use file-specific tools
以下情况请勿使用本Skill:
  • 复杂正则表达式操作 → 直接使用sed/awk
  • 文件编码转换 → 使用iconv
  • 二进制文件处理 → 使用特定文件工具

Commands

命令

Statistics

统计功能

bash
{baseDir}/text.sh stats <file>
{baseDir}/text.sh stats --stdin < file.txt
echo "text" | {baseDir}/text.sh stats --stdin
bash
{baseDir}/text.sh stats <file>
{baseDir}/text.sh stats --stdin < file.txt
echo "text" | {baseDir}/text.sh stats --stdin

Transform Case

大小写转换

bash
{baseDir}/text.sh upper <file>
{baseDir}/text.sh lower <file>
{baseDir}/text.sh title <file>
{baseDir}/text.sh sentence <file>
bash
{baseDir}/text.sh upper <file>
{baseDir}/text.sh lower <file>
{baseDir}/text.sh title <file>
{baseDir}/text.sh sentence <file>

Clean Text

文本清理

bash
{baseDir}/text.sh trim <file>
{baseDir}/text.sh dedup <file>
{baseDir}/text.sh strip-blank <file>
{baseDir}/text.sh normalize-spaces <file>
bash
{baseDir}/text.sh trim <file>
{baseDir}/text.sh dedup <file>
{baseDir}/text.sh strip-blank <file>
{baseDir}/text.sh normalize-spaces <file>

Sort & Unique

排序与去重

bash
{baseDir}/text.sh sort <file>
{baseDir}/text.sh sort --reverse <file>
{baseDir}/text.sh sort --numeric <file>
{baseDir}/text.sh unique <file>
{baseDir}/text.sh unique --count <file>
bash
{baseDir}/text.sh sort <file>
{baseDir}/text.sh sort --reverse <file>
{baseDir}/text.sh sort --numeric <file>
{baseDir}/text.sh unique <file>
{baseDir}/text.sh unique --count <file>

Find & Replace

查找与替换

bash
{baseDir}/text.sh replace <file> "old" "new"
{baseDir}/text.sh replace <file> --regex "pat.*tern" "replacement"
{baseDir}/text.sh replace <file> --ignore-case "OLD" "new"
bash
{baseDir}/text.sh replace <file> "old" "new"
{baseDir}/text.sh replace <file> --regex "pat.*tern" "replacement"
{baseDir}/text.sh replace <file> --ignore-case "OLD" "new"

Encoding

编码

bash
{baseDir}/text.sh encode base64 <file>
{baseDir}/text.sh encode url <file>
{baseDir}/text.sh encode html <file>
{baseDir}/text.sh encode hex <file>
bash
{baseDir}/text.sh encode base64 <file>
{baseDir}/text.sh encode url <file>
{baseDir}/text.sh encode html <file>
{baseDir}/text.sh encode hex <file>

Decode

解码

bash
{baseDir}/text.sh decode base64 <file>
{baseDir}/text.sh decode url <file>
{baseDir}/text.sh decode html <file>
{baseDir}/text.sh decode hex <file>
bash
{baseDir}/text.sh decode base64 <file>
{baseDir}/text.sh decode url <file>
{baseDir}/text.sh decode html <file>
{baseDir}/text.sh decode hex <file>

Options

选项

  • --stdin
    : Read from stdin instead of file
  • --out <file>
    : Write to file instead of stdout
  • --regex
    : Use regex pattern for replace
  • --ignore-case
    : Case-insensitive matching
  • --reverse
    : Reverse sort order
  • --numeric
    : Numeric sort
  • --count
    : Show count with unique
  • --stdin
    : 从stdin读取而非文件
  • --out <file>
    : 写入文件而非stdout
  • --regex
    : 替换时使用正则表达式模式
  • --ignore-case
    : 不区分大小写匹配
  • --reverse
    : 反转排序顺序
  • --numeric
    : 数值排序
  • --count
    : 显示去重后的计数

Examples

示例

Count words, lines, characters:
bash
{baseDir}/text.sh stats document.txt
统计字数、行数、字符数:
bash
{baseDir}/text.sh stats document.txt

Output: Lines: 100, Words: 500, Chars: 3000

Output: Lines: 100, Words: 500, Chars: 3000


**Remove duplicate lines:**
```bash
{baseDir}/text.sh dedup data.txt
Sort and count duplicates:
bash
{baseDir}/text.sh unique --count log.txt

**移除重复行:**
```bash
{baseDir}/text.sh dedup data.txt
排序并统计重复项:
bash
{baseDir}/text.sh unique --count log.txt

Output: 42 error

Output: 42 error

15 warning

15 warning

5 info

5 info


**URL decode:**
```bash
{baseDir}/text.sh decode url --stdin <<< "hello%20world"

**URL解码:**
```bash
{baseDir}/text.sh decode url --stdin <<< "hello%20world"

Output: hello world

Output: hello world

undefined
undefined

Notes

注意事项

  • All commands can read from stdin with
    --stdin
  • Original files are never modified (output to stdout)
  • Use
    --out
    to save to a file
  • 所有命令均可通过
    --stdin
    从stdin读取输入
  • 原始文件不会被修改(输出到stdout)
  • 使用
    --out
    选项将结果保存到文件