> For the complete documentation index, see [llms.txt](https://docs.gpmautomate.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gpmautomate.com/automate-zh/cao-zuo-zhi-nan/file-and-folder/read-random-line.md).

# 文件读取随机行

文件随机读取行是指打开一个现有的 `.txt` 文本文件，自动随机抽取该文件中的一行，然后将抽取的行内容保存到一个输出变量中。

这个动作在你管理社交媒体账户（Facebook、X、Instagram...）时非常有用，可以随机获取一条评论（Comment）、一条状态（Status）或一个搜索关键词，以避免在不同的个人资料之间重复相同的内容。

#### 配置参数：

* 文件路径：指向计算机上现有数据列表的 `.txt` 文件的绝对路径。
* 输出变量：保存刚刚抽取的随机行内容的变量名称。

#### 实际示例：自动随机评论以避免垃圾邮件

假设你准备了一个积极评论列表的文件，存放在 `D:\GPM\comments.txt`，每条评论占一行：

```
这篇文章真不错！
太棒了！
信息非常有用，谢谢楼主。
```

当脚本导航到一篇文章并准备点击评论时，你可以这样配置：

* 配置方式：
  * 调用文件随机读取行的动作。
  * 文件路径：填写路径 `D:\GPM\comments.txt`。
  * 输出变量：将结果变量命名为 `$randomComment`。
* 结果：每次流程运行到这一步（或每个个人资料独立运行时），系统将自动随机抽取上述三行中的一行（例如：个人资料 1 抽中第 3 行：`"信息非常有用，谢谢楼主。"` 并赋值给变量 `$randomComment`）。你只需调用按键操作将该变量传入网站的评论框即可。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.gpmautomate.com/automate-zh/cao-zuo-zhi-nan/file-and-folder/read-random-line.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
