2012-09-15 42 views
0

好的說我有2個文本文檔,一個包含文檔的名稱,另一個包含指向該文檔的鏈接。一種添加代碼並連接在一起的方法?

有沒有一種方法/程序或bash代碼,讓我做這一切走到一起,所以它看起來像這樣

<li class="pureCssMenui"><a class="pureCssMenui" href="https://docs.google.com/open?id=0B_KBy1Yc657LdnR5MGFXWVZZcnc" target="_blank">Cocoa in a nutshell.chm</a></li> 

所以我想補充

<li class="pureCssMenui"><a class="pureCssMenui" href=" to the beginning of each line in th links doc 

然後

target="_blank"> 

到標題文檔的開頭當然加

</a></li> 

到最後,它會全部聚集在一起。

此外,鏈接和標題已經與每個文檔中的行號相匹配。

+0

你聽說過[PHP](http://php.net)? –

+0

是 - 什麼語言? :-D – stefanglase

+0

@MadaraUchiha - PHP可以工作,但針對Web應用程序。 BASH會更有意義,因爲它已經被提及,或者任何通用腳本語言。 –

回答

0

只是爲了好玩:

$ cat file1 file2 
hello.doc 
world.xls 
plaintext-is-better.txt 
extensionsareforsuckers 
http://loldoc.com/phileurl 
http://spreadsheetfactory.uk/mooooooooo 
http://onlinetext.org/files/109874 
http://extensionssuck.info/4u373 

$ for i in {1..4}; do \ 
    sed -n $i'p' file1 | tr '\n' '|';\ 
    sed -n $i'p' file2 ;done |\ 
    awk -F\| '{printf "<a href=%s>%s</a>\n", $2, $1 }' 
<a href=http://loldoc.com/phileurl>hello.doc</a> 
<a href=http://spreadsheetfactory.uk/mooooooooo>world.xls</a> 
<a href=http://onlinetext.org/files/109874>plaintext-is-better.txt</a> 
<a href=http://extensionssuck.info/4u373>extensionsareforsuckers</a> 
相關問題