Heim  >  Artikel  >  Backend-Entwicklung  >  shell随机写入指定文件

shell随机写入指定文件

WBOY
WBOYOriginal
2016-06-06 20:45:281023Durchsuche

具体思路如下,求代码
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>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn