Issue
I am trying to group the search result by the patterns that I am searching after, but I can only get to results by files.
This is the closest I got:
grep -orE "btn-gray|btn-outline-white" ../../front/src/components | uniq -c
Which gives me this result:
8 ../../front/src/components/UI/Demo/RzDemoButtons.vue:btn-outline-white
4 ../../front/src/components/UI/Demo/RzDemoTabs.vue:btn-outline-white
1 ../../front/src/components/UI/Elements/Filters/RzFilter.vue:btn-outline-white
1 ../../front/src/components/MessagingCenter/MessageDetails/DetailsEmail.vue:btn-gray
4 ../../front/src/components/MessagingCenter/MessageDetails/DetailsEmail.vue:btn-outline-white
But I would need a result like:
btn-gray::8
btn-outline-white::13
Solution
I think it can be done via awk
, I'm not sure so please test it and let me know the result!
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}'
desired result :
btn-gray::1
btn-outline-white::13
Answered By - Freeman Answer Checked By - Timothy Miller (WPSolving Admin)