問題是plain text URL to HTML code (Automator/AppleScript)的續集。替換文本文件中,使用AppleScript和sed
假設我有一個簡單的txt文件/Users/myname/Desktop/URLlist.txt:(http://..)
title 1
http://a.b/c
title 2
http://d.e/f
...
我想(1)將所有的URL到HTML代碼, (2)添加
<br />
到每個空行,所以,前述內容將變得:
title 1
<a href="http://a.b/c">http://a.b/c</a>
<br />
title 2
<a href="http://d.e/f">http://d.e/f</a>
<br />
...
我來到以下Applescript:
set inFile to "/Users/myname/Desktop/URLlist.txt"
set middleFile to "/Users/myname/Desktop/URLlist2.txt"
set outFile to "/Users/myname/Desktop/URLlist3.txt"
do shell script "sed 's/\\(http[^ ]*\\)/<a href=\"\\1\">\\1<\\/a>/g' " & quoted form of inFile & " >" & quoted form of middleFile
do shell script "sed 's/^$/\\ <br \\/>/g' " & quoted form of middleFile & " >" & quoted form of outFile
它的工作,但它是多餘的(和愚蠢?)。任何人都可以使它更簡潔嗎?可以只涉及一個文本文件而不是三個(即/Users/myname/Desktop/URLlist.txt中的原始內容被最終結果覆蓋)?
非常感謝您提前。
+1對於模型樣本問題,帶有樣本輸入,需要的輸出和樣本代碼(gasp)。繼續發帖,祝你好運! – shellter