Shell提取破坏了URL

时间:2016-04-28 12:13:18

标签: shell awk sed

我是shell脚本新手。我通过python从邮件中提取一些URL,但是脚本解码的URL被破坏了。所以我想的是编写一个代码,以便我只能提取所需的URL。

这是文件:

http://stackoverflow.com/questions/17988756/=
how-to-select-lines-between-two-marker-patterns-which-may-occur-multiple-times-w
.
.
.(some text)
http://stackoverflow.com/questions/9605232/=
merge-two-lines-into-one
.
.
.

所需的输出是:

http://stackoverflow.com/questions/17988756/how-to-select-lines-between-two-marker-patterns-which-may-occur-multiple-times-w
http://stackoverflow.com/questions/9605232/merge-two-lines-into-one

提前致谢。

1 个答案:

答案 0 :(得分:2)

使用此sed

sed ':loop; /^http:.*=$/{N;s/=\n//g; t loop}' file

测试:

$ cat file
(some text)
http://stackoverflow.com/questions/9605232/=
merge-two-lines=
-into-one
(some text)

$ sed ':loop; /^http:.*=$/{N;s/=\n//; t loop}' file
(some text)
http://stackoverflow.com/questions/9605232/merge-two-lines-into-one
(some text)