这是与另外一个问题/代码高尔夫我问上Code golf: "Color highlighting" of repeated textshell脚本查找,搜索和
我有具有以下内容的文件“sample1.txt”文件替换字符串数组:
LoremIpsumissimplydummytextoftheprintingandtypesettingindustry.LoremIpsumhasbeentheindustry'sstandarddummytexteversincethe1500s,whenanunknownprintertookagalleyoftypeandscrambledittomakeatypespecimenbook.
我有一个脚本生成的字符串的下面阵列(只有少数为了说明示出),其发生在文件中:
LoremIpsum
LoremIpsu
dummytext
oremIpsum
LoremIps
dummytex
industry
oremIpsu
remIpsum
ummytext
LoremIp
dummyte
emIpsum
industr
mmytext
我需要(从顶部)看到如果'loremIpsum'出现在文件sample1.txt中。如果是这样,我想用以下代码替换所有的LoremIpsum:。现在,当程序移动到下一个单词'LoremIpsu'时,它不应该与sample1.txt中的文本匹配。它应该重复上面这个'数组'的所有元素。下一个'有效'的将是'dummytext',并且应该被标记为<T2>dummytext</T2>
。
我认为应该可以为此创建一个bash shell脚本解决方案,而不是依靠perl/python/ruby程序。
这听起来像SED工作,但问题是我不明白。 – Marco 2010-07-10 07:18:52
嗨马可 - T2的例子有帮助吗? – RubiCon10 2010-07-10 07:20:23
你为什么要使用shell脚本?为什么不使用最适合工作的工具? Perl是用于低编程时文本处理的。 – Borealid 2010-07-10 07:27:02