脚本的关键字

问题描述:

后需要删除文本我有一个像一堆URL的txt文件:脚本的关键字

http://url1.com/folder1/folder2 
http://url3.com/folder1/folder2 
http://url2.com/folder1/folder2 

林寻找一个脚本“.COM”后,将删除所有内容。似乎会有一个简单的applescript为此,但我似乎无法找到我在找什么。有任何想法吗?

+0

不知道? – mcgrailm 2011-05-16 12:36:28

上CBZ答案建筑,为什么你这个标记与PHP和JavaScript,以及你可以通过AppleScript的运行他的指挥下一些操作

-- choose afile you could also set this to a variable 
set infile to choose file 

--lets find out where the file lives so we know where to save the output to 
tell application "Finder" to set outpath to quoted form of POSIX path of (container of infile as text) 

-- convert the path of file to something shell can understand 
set infile to quoted form of POSIX path of infile 

--add file name to outpth 
set outfile to outpath & "parsed_text.txt" 

--put it all together and go, note I rearrange the command so that it will generate the results to a new file 
do shell script "sed -e 's,.com/.*$,.com,gw " & outfile & "' " & infile 

SED -e “S,.COM /.*$,.COM,G” < INFILE> OUTFILE

这里有一个在PHP。你也可以使用正则表达式,但我觉得使用parse_url可以让你继续使用它,而不必担心任何特殊情况弹出。

<?php 
$lines = file('yourfile.txt'); 
$sites = ''; 
foreach($lines as $url) { 
    $parsed = parse_url($url); 
    $sites .= $parsed['scheme']."://".$parsed['host']."/\n"; 
} 
file_put_contents('yournewfile.txt', $sites); 
?>