Shell提取断开的URL';s

Shell提取断开的URL';s,shell,awk,sed,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

我不熟悉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

提前感谢。

使用此
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)

我试着写一些代码:当IFS=read-r LINE do if[[$LINE=~^.*]]然后echo$LINE>>breaked\u URL.txt echo$[LINE+1]>>breaked\u URL.txt fi donebreaked\u new\u url.txt请将您的代码放在原始帖子中,以便保留格式。作为旁注,
http://stackoverflow.com/questions/17988756
单独是一个有效的URL。无论你从
stackoverflow.com/questions//XXX
XXX
中写什么都是无关紧要的,都会转到“stackoverflow.com/questions/”。@Ritzz,很高兴它对你有用。如果这个答案有帮助,考虑通过点击答案左边的刻痕来接受它。