怎样可以较快的将下面的文件处理,得到结果:docm、docx、dotm、dotx、potm、potx、ppam、ppsm、ppsx、pptm、pptx、xlam、xlsb、xlsm、xlsx、xltm、xltx、
".docm","application/vnd.ms-word.document.macroEnabled.12"
".docx","application/vnd.openxmlformats-officedocument.wordprocessingml.document"
".dotm","application/vnd.ms-word.template.macroEnabled.12"
".dotx","application/vnd.openxmlformats-officedocument.wordprocessingml.template"
".potm","application/vnd.ms-powerpoint.template.macroEnabled.12"
".potx","application/vnd.openxmlformats-officedocument.presentationml.template"
".ppam","application/vnd.ms-powerpoint.addin.macroEnabled.12"
".ppsm","application/vnd.ms-powerpoint.slideshow.macroEnabled.12"
".ppsx","application/vnd.openxmlformats-officedocument.presentationml.slideshow"
".pptm","application/vnd.ms-powerpoint.presentation.macroEnabled.12"
".pptx","application/vnd.openxmlformats-officedocument.presentationml.presentation"
".xlam","application/vnd.ms-excel.addin.macroEnabled.12"
".xlsb","application/vnd.ms-excel.sheet.binary.macroEnabled.12"
".xlsm","application vnd.ms-excel.sheet.macroEnabled.12"
".xlsx","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
".xltm","application/vnd.ms-excel.template.macroEnabled.12"
".xltx","application/vnd.openxmlformats-officedocument.spreadsheetml.template"
用perl不行么?
use strict ;
my $str ='
".docm","application/vnd.ms-word.document.macroEnabled.12"
".docx","application/vnd.openxmlformats-officedocument.wordprocessingml.document"
".dotm","application/vnd.ms-word.template.macroEnabled.12"
".dotx","application/vnd.openxmlformats-officedocument.wordprocessingml.template"
".potm","application/vnd.ms-powerpoint.template.macroEnabled.12"
".potx","application/vnd.openxmlformats-officedocument.presentationml.template"
".ppam","application/vnd.ms-powerpoint.addin.macroEnabled.12"
".ppsm","application/vnd.ms-powerpoint.slideshow.macroEnabled.12"
".ppsx","application/vnd.openxmlformats-officedocument.presentationml.slideshow"
".pptm","application/vnd.ms-powerpoint.presentation.macroEnabled.12"
".pptx","application/vnd.openxmlformats-officedocument.presentationml.presentation"
".xlam","application/vnd.ms-excel.addin.macroEnabled.12"
".xlsb","application/vnd.ms-excel.sheet.binary.macroEnabled.12"
".xlsm","application vnd.ms-excel.sheet.macroEnabled.12"
".xlsx","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
".xltm","application/vnd.ms-excel.template.macroEnabled.12"
".xltx","application/vnd.openxmlformats-officedocument.spreadsheetml.template"' ;
while($str =~ m/("\.[a-z]{4}"),/g){
print $1, "\n" ;
}
vim的方法,
思路,首先我们要找到形如.xxxx的模式,然后将整行的内容替换为这个模式即可。
:%s/\"\.\(\a\{4}\).*/\1/g
解释一下
% 全局替换
s 替换
\" 匹配"
\. 匹配.
\(\)匹配组
\a 匹配任意英文字母
\{4}重复4次
.*匹配后面所有内容
\1第一个匹配
谢谢,不过最好还是把换行符也去掉,最后成这样的结果:
docm、docx、dotm、dotx、potm、potx、ppam、ppsm、ppsx、pptm、pptx、xlam、xlsb、xlsm、xlsx、xltm、xltx、
所以我修改了你的代码:
:%s/\"\.\(\a\{4}\).*\n/\1、/g