Now that I have given all this background on how I started using the Shell, here is the specific case. I was working on a Grails project and we found an error that was being created in all files that were doing a specific thing. Rather then look through all the files manually I was able to come up with these scripts to help me identify the affected files and also to then replace the affected lines.
This first script is what I came up with to find all the files with the issue. I did a grep of all files in the views directory that contained actionSubmit. I pipe those files to show the line that has action= I then use sed to remove the action= from the line, sort it, uniq it, then use awk to display the information
grep -R "actionSubmit" views/* | grep -o 'action=\"[a-zA-Z]*' | sed 's/action="//' | sort | uniq | awk '{print " def " $1 " = { \n error()\n }\n";}'This is similar to the above but I use find to return all the files under views then grep each one for the actionSubmit to get the items and the counts this is then piped through grep for the line and displayed.
find views/ -type f -exec sh -c "grep -l actionSubmit {}; grep -c actionSubmit {}; grep actionSubmit {} | grep -o 'action=\"[a-zA-Z]*' | sed 's/action=\"//'" \;
No comments:
Post a Comment