[英]grep to extract out regular expression href and rel from html
我正在處理的html看起來像這樣
<a class="title may-blank" data-event-action="title" href="/r/gaming/comments/6t8dj0/we_can_play_singleplayer_games_off_the_internet/" tabindex="1" data-href-url="/r/gaming/comments/6t8dj0/we_can_play_singleplayer_games_off_the_internet/" data-inbound-url="/r/gaming/comments/6t8dj0/we_can_play_singleplayer_games_off_the_internet/?utm_content=title&utm_medium=hot&utm_source=reddit&utm_name=frontpage" rel="">We can play singleplayer games OFF THE INTERNET? Are they seriously that out of touch to advertise this?</a>
這樣的多行
我只想要href="http://xxxxxxxx"
和rel="">yyyyyyyyyy
的引號之間的rel="">yyyyyyyyyy
,其余的都是不必要的。
我希望他們像這樣輸出,上面的每個塊都換一行
<a href="http://xxxxxxxx" rel="">yyyyyyyyyy</a>
知道我該如何解決嗎?
因此,這是一個10秒鍾的解決方案。 它可能有點脆弱,但是應該假設字符串在名為html.txt的文件中就可以工作
cat html.txt | sed 's/class.*href/href/' | sed 's/data-in.*rel=/rel=/'
Ĵ
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.