Regex 来自cURL html的多个标记中的GREP数据
非常渴望了解如何从Regex 来自cURL html的多个标记中的GREP数据,regex,bash,sed,awk,grep,Regex,Bash,Sed,Awk,Grep,非常渴望了解如何从curl命令中获取所需的数据 我需要一个生成grep命令的助手来获得以下html: <title> timetable </t itle>< <h3>study table</h3> <p>< strong>biology <div> <table width='100%' cellpadding='5' cellspacing='0'><tr><th col
curl
命令中获取所需的数据
我需要一个生成grep
命令的助手来获得以下html
:
<title> timetable </t itle>< <h3>study table</h3> <p>< strong>biology <div> <table
width='100%' cellpadding='5' cellspacing='0'><tr><th colspan="3">Level 44 Building 1 <tr>
<td >monday</td> <td >1:30 – 2:30</td> <td >< a>Room number 22</a></td> <td > </td>
</tr> <tr><th colspan="2">body> </html>
目前我只知道如何执行单个grep
,例如:
grep 'href='
假设字符串位于变量
$data
中,则可以:
IFS=$'\n'
result=$(echo $data | sed 's/&[^;]*;//')
result=$(echo $result | sed 's/<[^>]*>/\n/g')
for string in $result; do
if [[ ! $string =~ ^\ *$ ]]; then
echo "string=$string."
fi
done
IFS=$”\n
结果=$(echo$data | sed's/&[^;]*;//')
结果=$(echo$result | sed's/]*>/\n/g')
对于$result中的字符串;做
如果[!$string=~^\*$];然后
echo“string=$string”
fi
完成
如果您有GNU grep:
$ grep -Po '(?<=>) ?\K[^<&>]{2,}(?=<)' file
timetable
study table
biology
Level 44 Building 1
monday
1:30 – 2:30
Room number 22
$grep-Po'(?)?\K[^]{2,}(?=使用xml/html解析器。
$ grep -Po '(?<=>) ?\K[^<&>]{2,}(?=<)' file
timetable
study table
biology
Level 44 Building 1
monday
1:30 – 2:30
Room number 22