shell随机写入指定文件

WBOY
Release: 2016-06-06 20:45:28
Original
1023 people have browsed it

具体思路如下,求代码
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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!