> 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/action-shi-yong-zhi-nan/file-and-folder/file-read-random-line.md).

# File read random line

File read random line 是用于打开一个现有的 `.txt` 文本文件的操作,自动从该文件中随机抽取任意一行,然后将抽取到的该行内容保存到一个输出变量中。

当您在养号社交媒体账户(Facebook、X、Instagram...)并希望随机获取一句评论(Comment)、一句状态(Status)或一个搜索关键词时,此操作非常有用,可以避免各个 Profile 之间脚本重复相同的内容。

🎥 观看更多教学视频:[点击这里](https://youtu.be/EH7olDLAb9c)。

#### 配置参数:

* File Path:指向计算机上包含现有数据列表的 `.txt` 文件的绝对路径。
* Output variable:用于保存刚抽取到的随机行内容的变量名称。

#### 实际示例:自动随机评论以避免刷屏

假设您已准备好一个保存在 `D:\GPM\comments.txt` 的积极评论列表文件,每句话单独占一行:

```
Bài viết hay quá bạn ơi!
Tuyệt vời quá ạ.
Thông tin rất bổ ích, cảm ơn chủ thớt.
```

当脚本将浏览器导航到某篇帖子并准备点击评论时,您可以按如下方式配置:

* 配置方法:
  * 调用 File read random line 操作。
  * File Path:填入路径 `D:\GPM\comments.txt`。
  * Output variable:将保存结果的变量命名为 `$randomComment`。
* 结果:每次流程运行到此步骤时(或每个 Profile 独立运行时),系统将自动随机抽取上述 3 行中的其中 1 行(例如:Profile 1 抽中第 3 行:`"Thông tin rất bổ ích, cảm ơn chủ thớt."`,并将其赋值给变量 `$randomComment`)。您只需调用 Key press 操作,将该变量传入网站上的评论框即可完成。

<figure><img src="/files/BkgclbF4vlGVbwYl7nYX" alt=""><figcaption></figcaption></figure>


---

# 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/action-shi-yong-zhi-nan/file-and-folder/file-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.
