如何使用grep来收集URL链接?

假设我有一个名为plaintext.txt的文件,它有2行和一个内容

you can be social online by logging in to http://www.facebook.com and http://plus.google.com alternatively, you can also create an account in http://www.twitter.com 

我知道我可以通过在命令行中发出cat语句来显示文件的全部内容

 cat plaintext.txt 

我想从明文收集所有的URL链接,以便我可以显示

 http://www.facebook.com http://plus.google.com http://www.twitter.com 

我认为这个命令行语句是这样的

 cat plaintext.txt | grep something 

但我不完全知道如何。

如何使用grep来收集URL链接?

 sed 's/\s/\n/g' plaintext.txt | grep http: 

其中plaintext.txt是包含你的两行的文件。

你可以使用grep -o选项。

 $ cat file you can be social online by logging in to http://www.facebook.com and http://plus.google.com alternatively, you can also create an account in http://www.twitter.com 

 $ grep -o "http[^ ]*" file http://www.facebook.com http://plus.google.com http://www.twitter.com 

man page

 -o, --only-matching Show only the part of a matching line that matches PATTERN.