【问题标题】:how to read a random line from 2 files and put them together如何从 2 个文件中读取随机行并将它们放在一起
【发布时间】:2016-08-16 19:42:43
【问题描述】:

所以我在 bash 中尝试了 shuf -n 1 filename,它显示了一条随机线,但我希望能够在我自己的网站上使用 2 个文件和输出组合来执行此操作。

例如我的文件是

file 1
one one
five eight
one two three

file 2 
canada
usa
netherland

所以输出将是“五八美国”或“一一荷兰”

有谁知道任何代码可以帮助我开始这个?

【问题讨论】:

  • 您有哪些服务器端语言功能? php、asp等?
  • 我将使用 wordpress 或 wix 开始

标签: html wordpress bash


【解决方案1】:

使用 paste、shuf 和 bash 的进程替换:

paste -d " " <(shuf -n 1 file1) <(shuf -n 1 file2)

输出(示例):

一二三加拿大

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多