Linux 查找与regex的链接
我目前正在尝试学习Linux命令和正则表达式,我遇到了一个小问题,我试图使用sed和正则表达式在文件中查找一系列链接,有人能帮我解决这个问题吗?我哪里出了问题。链接是这样的Linux 查找与regex的链接,linux,sed,Linux,Sed,我目前正在尝试学习Linux命令和正则表达式,我遇到了一个小问题,我试图使用sed和正则表达式在文件中查找一系列链接,有人能帮我解决这个问题吗?我哪里出了问题。链接是这样的 <a href="../a-lot-of-different/words-that/should-link.html">Useful links</a> <a href="..//a-lot-of-different/words-that/should-find-lots-of-links.ht
<a href="../a-lot-of-different/words-that/should-link.html">Useful links</a>
<a href="..//a-lot-of-different/words-that/should-find-lots-of-links.html">Multiple links</a>
<a href="../another-word-and-links/multiple-words/sjshfi-dfg.html">more links</a>
这就是我所拥有的
sed -n '/<a*href=”^[../"]*\([a-z]*\)^[.html](["]*\)/p' /file > newfile
sed-n'/正则表达式不太适合解析HTML
您没有显示所需的输出。我猜你想提取链接。如果是,请尝试:
$ sed -rn 's/.*<a\s+href="([^"]*)".*/\1/p' file
../a-lot-of-different/words-that/should-link.html
..//a-lot-of-different/words-that/should-find-lots-of-links.html
../another-word-and-links/multiple-words/sjshfi-dfg.html
$sed-rn的/*由于锚定标记包含href
标记,因此搜索href
将解决此问题
sed -n '/href=".*"/p' link_file.txt
如果是HTML文件,我建议使用DOM解析器。看到了,谢谢你,这让它更清晰了,它找到了我正在寻找的一个链接。