find a file by content with line number on unix linux platform

Find a file on linux/ unix/ cygwin platform by the content. This inline script will give the name of the file, line number of searched text in nested directories.
Find command adds the selection of file and can be used to accommodate others variations like since date modified, file type etc.

 find . -name "*.java" -exec grep -H -n "express" '{}' \;  

Example Output

./com/abc/HttpRequestInterceptor.java:120:           if (StringUtils.isEmpty(request.getHeader("express"))) {
./com/abc/HttpRequestInterceptor.java:123:           if (!request.getHeader("xxxxx").equalsIgnoreCase("true")) {
./com/abc/xyz.java:10: *  either expressed or implied.
./com/xxxx/abc.java:282:         
String expression = "^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$";
./com/xxxxx/AddressChangeUtil.java:284:           Pattern pattern = Pattern.compile(expression);
./com/xxxxx/changecontact/ChangeContactSaveHelper.java:64:              String expression = "^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$";
./com/xxxxx/ChangeContactSaveHelper.java:66:              Pattern pattern = Pattern.compile(expression);

Comments

Popular posts from this blog

Caused by: java.sql.SQLTimeoutException: ORA-01013: user requested cancel of current operation

pandas dataframe add missing date from range in a multi-dimensional structure with duplicate index

Delete horizontal, vertical and angled lines from an image using Python to clear noise and read text with minimum errors