简体   繁体   English

Linux中的sed命令

[英]Sed command in linux

How do I extract URL's from a file? 如何从文件中提取URL? My file name is URL_name.txt This file has a lot of url inside. 我的文件名为URL_name.txt此文件内部有很多url。 It looks like this: 看起来像这样:

<pre>
<pre><div></pre><something>something here<href="http://www.google.com/">something here</font>
<font><href="http://www.stackoverflow.com/">something</td>

..
..
..
</pre>

Here is my idea, I want to remove everything before URLs then I can remove everything after URL. 这是我的想法,我想删除URL之前的所有内容,然后删除URL之后的所有内容。 How do I use sed command deal with it? 我如何使用sed命令处理它? The output should be 输出应为

http://www.google.com/
http://www.stackoverflow.com/

使用trgrep

tr '"' '\n' < URL_name.txt | grep http

It is possible using java. 可以使用Java。 as well as you can also try below commands: 您也可以尝试以下命令:

  1. egrep -ie "<*HREF=(.*?)>" index.html | cut -d "\\"" -f 2 | grep ://
  2. egrep -ie "<*HREF=(.*?)>" index.html | awk -F\\" '{print $2}' | grep ://

您可以使用grep

grep -o 'http://[^"]*' yourfile

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM