In PHP I use grep
to search and count all cases of certain classes in almost all files.
\exec("grep -orE '" . $classesBarred . "' ../../front/src/components | sort | uniq -c", $allClassesCount);
where $classesBarred
contains class strings similar to search-unfocused|bg-app|enlarged-window
(but more).
The current result is
' 2 ../../front/src/components/Actions/ActionOwner.vue:show', ' 1 ../../front/src/components/Actions/ActionOwner.vue:action', ' 1 ../../front/src/components/Actions/ActionOwner.vue:show', ' 5 ../../front/src/components/Actions/ActionOwner.vue:action', ' 1 ../../front/src/components/Actions/ActionOwner.vue:show', ....(还有几百行类似的结果)
I need to save the results in an array, similar to:
[ {show: 38}, {action: 123}, {search-unfocused: 90}, {....} ]
edit:
@Freeman provided a solution here, using awk
grep -orE "btn-gray|btn-outline-white" ../../front/src/components | awk -F: '{print$2}' | awk -F/ '{print $NF}' |sort| uniq-c| awk '{print $2 "::" $1}'
The following results were obtained:
btn-gray::1 btn-outline-white::13
Yes, I can see that your code uses
awk
to rearrange the output ofgrep
into two columns, one column is the class name and the other is the count, The output results are as follows:Now you can parse this output into an array through PHP, the code is as follows:
The results of the array are as follows:
renew:
If you insist on using awk and sed, you can do this:
The results are as follows:
rrreeeGood luck!