简体   繁体   中英

How can I find text after some string over bash

I have this bash script and works

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

<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. But this number is amended. When you run the script eg per month, it may be different

I do not have the "cat" command. I have receiver and not linux. Receiver have enigma system and "cat" isn´t implemented

I tested through comparison "sed", but it does not work.

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" 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 :

$ 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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