bash grep“随机匹配"字符串
是否可以通过bash从文本文件中获取随机匹配"字符串?
Is there a way to grab a 'random matching' string via bash from a text file?
我目前正在通过bash,curl& amp;抓取下载链接.在线文本文件中的grep.
I am currently grabbing a download link via bash, curl & grep from a online text file.
示例:
DOWNLOADSTRING="$(curl -o - "http://example.com/folder/downloadlinks.txt" | grep "$VARIABLE")"
包含以下内容的在线文本文件
from online text file which contains
http://alphaserver.com/files/apple.zip
http://alphaserver.com/files/banana.zip
其中$ VARIABLE是用户选择的内容.
where $VARIABLE is something the user selected.
效果很好,但我想在文本文件中添加一些镜像.
Works great, but i wanted to add some mirrors to the text file.
So when the variable 'banana' is selected, text file which i grep contains:
So when the variable 'banana' is selected, text file which i grep contains:
http://alphaserver.com/files/apple.zip
http://betaserver.com/files/apple.zip
http://gammaserver.com/files/apple.zip
http://deltaserver.com/files/apple.zip
http://alphaserver.com/files/banana.zip
http://betaserver.com/files/banana.zip
http://gammaserver.com/files/banana.zip
http://deltaserver.com/files/banana.zip
代码应选择一个随机的香蕉"字符串并将其存储为"DOWNLOADSTRING"变量.上面的当前代码只能在文本文件中使用1个字符串,因为它捕获了所有香蕉".
the code should pick a random 'banana' string and store it as the 'DOWNLOADSTRING' variable. the current code above can only work with 1 string in the text file, since it grabs everything 'banana'.
这是做什么的;我想为在线文本文件中的文件添加一些镜像下载链接,而当前代码不允许这样做.
What this is for; i wanted to add some mirror downloadlinks for the files in the online text file, and the current code doesn't allow that.
我可以让grep抓取一个随机的香蕉"字符串吗?(并非全部)
Can i let grep grab one random 'banana' string? (and not all of them)
请参阅此问题,以了解如何在grep之后获得随机行. rl
似乎是一个不错的候选人
See this question to see how to get a random line after grep. rl
seems like a good candidate
然后执行 grep ... |.rl |头-n 1