Home  >  Article  >  Backend Development  >  shell随机写入指定文件

shell随机写入指定文件

WBOY
WBOYOriginal
2016-06-06 20:45:281022browse

具体思路如下,求代码
shell随机读取file.txt文本,file.txt文本有许多行文字
想用shell随机读取file.txt的任意一行文字并且写入到file.php第四行文件。
谢谢。

回复内容:

具体思路如下,求代码
shell随机读取file.txt文本,file.txt文本有许多行文字
想用shell随机读取file.txt的任意一行文字并且写入到file.php第四行文件。
谢谢。

假设你的 file.txt 里没有特殊字符:

<code class="lang-bash">sed -i -e "4s/.*/$(sort -R file.txt | head -1)/" file.php
</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn