![](/img/trans.png)
[英]Python 2: Using regex to pull out whole lines from text file with substring from another
[英]parse text using grep regex pull out text from multiple lines of text in a file
我在文件中有一個文本塊:
<tr bgcolor="#F9F9F9">
<td align="left">8/7/2012 11:23:42 AM</td>
<td align="left"><em>Here is the text I want to parse out</em></td>
<td class="ra">9.00</td>
<td class="ra">297.00</td>
<td class="ra">0.00</td>
<td class="ra">0.00</td>
<td class="ra">$0.00</td>
<td class="ra">$0.50</td>
<td class="ra"></td>
</tr>
使用grep我想結果是結果
這是我要解析的文本
我現在正在處理代碼
cat file.txt | grep -m 1 -oP '<em>[^</em>]*'
但這不起作用...感謝您的幫助!
正確的正則表達式是(?<=<em>).*?(?=</em>)
。
所以,試試:
grep -m 1 -oP '(?<=<em>).*?(?=</em>)' file.txt
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.