find snippets

Find a text pattern in jar files

Tagged jar, find, search, recursive, linux, unzip  Languages bash

Helpful when you need to find a class or package in some jar file recursively below the current directory. Still needs a test to see if the file found was a file or directory. Works case insensitively. Uses the unzip command because of it's performance superiority in comparison to jar.

#!/bin/sh
for f in find . -type f -name '*\.jar'
do
        unzip -l $f | grep -i $1 && echo "was found in $f"
done

Search and replace file contents and file names

Tagged bash, find, replace, search  Languages bash

Search and replace file contents and file names

Note that all changes must be commited to git before running the command:

git grep -l 'observation' | xargs sed -i '' -e 's/observation/condition/g'

Search and replace of file names

find . -name '*observation*' -exec bash -c 'mv $0 ${0/observation/condition}' {} \;