练习awk!- # & cls & (for /f "delims=" %%a in ('dir/b/s d:\数据1\*.txt') do @gawk -f %0 %%a) & pause & exit
- #求全排列使用的“插入法”
- #注意:split函数产生空值的问题
- #如:split("a,",arr,","),生成的arr有两个元素,第二个元素为空值
- {
- #显示进度
- print "processing "FILENAME" row "NR
- s=$0;perm=""
- for(i=1;i<=length(s);i++){
- split(perm,arr,",");perm=""
- #开始perm为空,得到的arr也为空,为避免for(j in arr)不执行,初始一个空值
- if(length(arr)==0){arr[1]=""}
- word=substr(s,i,1)
- for(j in arr){
- for(k=0;k<=length(arr[j]);k++){
- tmp=substr(arr[j],1,k)""word""substr(arr[j],k+1,length(arr[j])-k)
- perm=perm""tmp","
- }
- }
- #去掉最后的分隔符",",以免split函数产生空值
- perm=substr(perm,1,length(perm)-1)
- }
- #将逗号换成换行符
- gsub(/,/,"\n",perm)
- #获得当前处理的文件名
- split(FILENAME,path,"\\")
- print perm >> "d:\\数据2\\"path[length(path)]
- }
复制代码
|