简体   繁体   English

如何在bash上输入一些字符串后找到文本

[英]How can I find text after some string over bash

I have this bash script and works 我有这个bash脚本并且可以工作

DIRECTORY='1.20_TRUNK/mips-tuxbox-oe1.6'

# Download html page and save to tmp folder to ump.tmp file
wget -O 'ump.tmp' 'http://download.oscam.cc/index.php?&direction=0&order=mod&directory=$DIRECTORY&'

ft='index.php?action=downloadfile&filename=oscam-svn'
st='-webif-Distribution.tar.gz&directory=$DIRECTORY&'

File ump.tmp containts eg three links 文件ump.tmp包含三个链接

<a href="index.php?action=downloadfile&amp;filename=oscam-svn10082-mips-tuxbox-webif-Distribution.tar.gz&amp;directory=$DIRECTORY&amp;"></a>

<a href="index.php?action=downloadfile&amp;filename=oscam-svn10081-mips-tuxbox-webif-Distribution.tar.gz&amp;directory=$DIRECTORY&amp;"></a>

<a href="index.php?action=downloadfile&amp;filename=oscam-svn10080-mips-tuxbox-webif-Distribution.tar.gz&amp;directory=$DIRECTORY&amp;"></a>

I need find solution for find only number 10082 in first "a" links of the page. 我需要在页面的第一个“ a”链接中仅找到数字10082的查找解决方案。 But this number is amended. 但是这个数字被修改了。 When you run the script eg per month, it may be different 当您运行脚本(例如每月)时,可能会有所不同

I do not have the "cat" command. 我没有“ cat”命令。 I have receiver and not linux. 我有接收器,而不是linux。 Receiver have enigma system and "cat" isn´t implemented 接收器具有谜题系统,并且未实现“ cat”

I tested through comparison "sed", but it does not work. 我通过比较“ sed”进行了测试,但是没有用。

sed -n "/filename=oscam-svn/,/-mips-tuxbox-webif/p" ump.tmp

"Find" is kind of vague, but you can use grep to get the link with the number 10082 in it from the temp file. “查找”有点含糊,但是您可以使用grep从临时文件中获取带有10082的链接。

$ grep "10082" ump.tmp
<a href="index.php?action=downloadfile&amp;filename=oscam-svn10082-mips-tuxbox-webif-Distribution.tar.gz&amp;directory=$DIRECTORY&amp;"></a>

Using a proper XHTML parser : 使用适当的XHTML解析器:

$ xmllint --html --xpath '//a/@href[contains(., "downloadfile")]' ump.tmp 2>/dev/null |
    grep -oP "oscam-svn\K\d+"

But there's not this string in the given HTML file 但是给定的HTML文件中没有此字符串

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM