3

使用 Sed,我想替换这条长线:

http://download.lenovo.com/UserFiles/Driver/en/Downloads%20and%20Drivers/Z570/Win7/IN3ETN46WW5.exehttp://download.lenovo.com/UserFiles/Driver/en/Downloads%20and%20Drivers/Z570/Win%207%20Update/IN1AUD25WW5.exehttp://download.lenovo.com/UserFiles/Driver/en/Downloads%20and%20Drivers/Z570/Win7/IN2VDO61WW6.exehttp://download.lenovo.com/UserFiles/Driver/en/Downloads%20and%20Drivers/Z570/Win7/IN1SRM38WW5.exehttp://download.lenovo.com/UserFiles/Driver/en/Downloads%20and%20Drivers/Z570/Win7/IN2VDO63WW5.exehttp://download.lenovo.com/UserFiles/Driver/en/Downloads%20and%20Drivers/Z570/Win7/IN6WLN49WW5.exe

进入这个:

http://download.lenovo.com/UserFiles/Driver/en/Downloads%20and%20Drivers/Z570/Win7/IN3ETN46WW5.exe
http://download.lenovo.com/UserFiles/Driver/en/Downloads%20and%20Drivers/Z570/Win%207%20Update/IN1AUD25WW5.exe
http://download.lenovo.com/UserFiles/Driver/en/Downloads%20and%20Drivers/Z570/Win7/IN2VDO61WW6.exe

我试过(在vim里面)

:%s#http://#\nhttp://#g 

它不起作用。

有什么建议么?

4

2 回答 2

3

For some reason vim wants \r in the replacement, so if you change your substitution to:

:%s#http://#\r&#g

it will work.

If you don't mind the extra whitespace, this will work in sed:

sed 's#http://#\n&#g' infile
于 2012-09-18T09:11:42.550 回答
0

如果多余的空格很烦人,您可以使用GNU awk

awk -F "http" '{ for (i=2; i<=NF; i++) print FS $i }' file.txt

结果:

http://download.lenovo.com/UserFiles/Driver/en/Downloads%20and%20Drivers/Z570/Win7/IN3ETN46WW5.exe
http://download.lenovo.com/UserFiles/Driver/en/Downloads%20and%20Drivers/Z570/Win%207%20Update/IN1AUD25WW5.exe
http://download.lenovo.com/UserFiles/Driver/en/Downloads%20and%20Drivers/Z570/Win7/IN2VDO61WW6.exe
http://download.lenovo.com/UserFiles/Driver/en/Downloads%20and%20Drivers/Z570/Win7/IN1SRM38WW5.exe
http://download.lenovo.com/UserFiles/Driver/en/Downloads%20and%20Drivers/Z570/Win7/IN2VDO63WW5.exe
http://download.lenovo.com/UserFiles/Driver/en/Downloads%20and%20Drivers/Z570/Win7/IN6WLN49WW5.exe
于 2012-09-19T00:12:05.353 回答