Combining find and grep

Quick note to remember this syntax as every few months I find a need to do a grep within a number of files:

find -name "pattern" -exec grep "pattern" {} ;

Grep options:
-H print filename in results
-n print line number where match was found
-l limit match to first found match in file (useful if you want to find files containing a match but don’t care how many matches are in each file)

Pipe to wc -l to count file occurrences, eg:

find -name "pattern" -exec grep -l "pattern" {} ; | wc -l

Use egrep if you need to use regex in the pattern.

Merging a new OpenShift project git repo with an existing local project repo

Steps mainly from here, assuming you already have a local git repo for an existing project and you want to merge it into a newly created project on OpenShift for deployment:

Add the remote openshift remote:

git remote add openshift_git_repo_url

Merge the content from the newly created repo into your existing project (this will be some pom.xml changes and the .openshift directory for remote server settings and triggers etc):

git merge openshift/master -s recursive -X ours

This didn’t do anything for me, it said ‘already up to date’, so I pulled down the files from the remote with:

git pull openshift master

which resulted in a couple of conflicts, like pom.xml. Update the files with conflicts to resolve them and commit the changes, then push back to the remote:

git push openshift master

Done!