跳到正文
cccskills
免费在 GitHub 公开

text-file

Guidelines for handling text files

中文简介正在准备中。当前显示原文说明。

查看安装方法

包含的文件(1)

  • SKILL.md2.5 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Text Files Handling Specifications

Goals

  • Safely read text files without memory exhaustion.
  • Accurately detect encoding to avoid garbled characters.
  • Identify underlying patterns (e.g., Log formats, Markdown structure, delimiters).
  • Efficiently extract or search for specific information within large volumes of text.

Encoding & Detection

  • Encoding Strategy:
    • Default to utf-8.
    • If it fails, try utf-8-sig (for files with BOM), gbk/gb18030 (for Chinese context), or latin-1.
    • Use chardet or similar logic if encoding is unknown and first few bytes look non-standard.
  • Line Endings: Be aware of \n (Unix), \r\n (Windows), and \r (Legacy Mac) when counting lines or splitting.

Inspection

  • Preview: Read the first 10-20 lines to determine:
    • Content Type: Is it a log, code, prose, or a semi-structured list?
    • Uniformity: Does every line follow the same format?
  • Metadata: Check total file size before reading. If >50MB, treat as a "large file" and avoid full loading.

Querying & Reading (Large Files)

  • Streaming: For files exceeding memory or >50MB:
    • Use with open(path) as f: for line in f: to process line-by-line.
    • Never use .read() or .readlines() on large files.
  • Random Sampling: To understand a huge file's structure, read the first N lines, the middle N lines (using f.seek()), and the last N lines.
  • Pattern Matching: Use Regular Expressions (Regex) for targeted extraction instead of complex string slicing.
  • Grep-like Search: If searching for a keyword, iterate through lines and only store/return matching lines + context.

Data Quality

  • Truncation Warning: If only a portion of the file is read, clearly state: "Displaying first X lines of Y total lines."
  • Empty Lines/Comments: Decide early whether to ignore blank lines or lines starting with specific comment characters (e.g., #, //).

Best Practices

  • Resource Safety: Always use context managers (with statement) to ensure file handles are closed.
  • Memory Consciousness: For logs and large TXT, prioritize "find and extract" over "load and filter."
  • Regex Optimization: Compile regex patterns if they are used repeatedly in a loop over millions of lines.
  • Validation: After reading, verify the content isn't binary (e.g., PDF or EXE renamed to .txt) by checking for null bytes or a high density of non-ASCII characters.
  • Progress Logging: For long-running text processing, log progress every 100k lines or 10% of file size.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Guidelines for handling CSV/Excel files

中文简介正在准备中。当前显示原文说明。

agentscope-ai/agentscope-samples3512026年4月10日 更新

database

免费

Guidelines for handling databases

中文简介正在准备中。当前显示原文说明。

agentscope-ai/agentscope-samples3512026年4月10日 更新

Guidelines for handling image files

中文简介正在准备中。当前显示原文说明。

agentscope-ai/agentscope-samples3512026年4月10日 更新

json-file

免费

Guildlines for handling json files

中文简介正在准备中。当前显示原文说明。

agentscope-ai/agentscope-samples3512026年4月10日 更新

查看 agentscope-ai 的全部技能

报告此技能的问题