Posts

Showing posts with the label unix linux

find a jar file by the name of class

A utility to find the text from archives. This strain is specifically useful for finding the particular jar file if it contains the given class. Use it freely on any Unix and Linux platform. for f in `find $1 -name "*.jar"` do if [ `jar tf $f | grep "class" | sed 's|/|.|g' | grep $2 | wc -l` -gt 0 ] ; then echo $f fi done Example usage: $ ./jarFinder . com.ibm.ws.webservices.engine.description.OperationDesc Output ./libs/Lib/com.ibm.ws.runtime.jar ./libs/Lib/com.ibm.ws.runtime.jar

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:        ...

Unix/Linux Inline command for extracting file and filetype

filetype=`echo $f | awk '{n=split($0, a, ".")} END{print a[n] }'` filename=`echo $f | awk '{n=split($0, a, "/")} END{print a[n] }'` where $f is the full path of the file. It can be used directly too as.. filetype=`echo "/home/myuser/a.b.c.d.txt" | awk '{n=split($0, a, ".")} END{print a[n] }'` output : txt filename=`echo "/home/myuser/a.b.c.d.txt" | awk '{n=split($0, a, "/")} END{print a[n] }'` output: a.b.c.d