鍍金池/ 問答/PHP  Linux/ linux多個(gè)文件夾和文件讀???

linux多個(gè)文件夾和文件讀???

比如有如下目錄:

app/test1/test1.tpl
app/test1/test2.tpl
app/test2/test1.tpl
app/test2/test2.tpl
app/test2/test3.tpl
app/test3/test1.tpl
...

讀取文件,把符合條件的行歸并到同一行。
比如:
test1文件夾里面的所有tpl文件符合的行全部合并到新文件的同一行。
test2文件夾里面的所有tpl文件符合的行全部合并到新文件另外一行。
求思路。

最后生成如下格式:

test1 function1 function2 fun fn 
test2 var let count // 第一個(gè)為文件夾的名稱,后面的為提取文件符合要求的單詞
test3 async await promise 

以下是我之前的過濾條件
find /home/work/src/app/* -name *.tpl|xargs -i{} sed -n '/component/{:a;N;/}/!ba;p}' {} |  grep ['search{}'] | sed "s/component://g;s/}//g;s/{//g;s/[ ]["\t"]*//g;s/,//g;s/'//g;s/\"http://g;s/\r\$//g" | awk -F [:/] '{print $NF}' | perl -ne 's/^\s*(\S+)\n$/\1 /g;print' | sed '/^$/d' > result.txt
回答
編輯回答
耍太極

有類似問題你搜一下

2017年2月12日 18:21
編輯回答
傻丟丟
#!/bin/bash
for dir in $(ls $1)
do
if [ -d "$1/$dir" ]
then
        row=$(cat $1/$dir/*.atom | awk 'BEGIN{FS="\n";RS="";ORS=" ";}{start=0;end=0;for(x=1;x<=NF;x++){if($x ~ /components:/){start = 1;}if(start == 1 && $x ~ /}/){end = 1;}if(start == 1 && end != 1 && $x !~ /^[\s\t]+$/ && $x !~ /components:/){num=split($x,a,"/");tmp=a[num];if(index(tmp,"\"")){split(tmp,b,"\"");}else{split(tmp,b,"'\''");}print b[1];} } }')
if [ -n "$row" ]
then
        echo "${dir} ${row}" >> 'result.txt'
fi
fi
done
2018年3月21日 17:14