Skip to content

Instantly share code, notes, and snippets.

@marcingrzejszczak
Created June 28, 2016 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcingrzejszczak/60b1cd18963cc53232abaf0557a6c4c8 to your computer and use it in GitHub Desktop.
Save marcingrzejszczak/60b1cd18963cc53232abaf0557a6c4c8 to your computer and use it in GitHub Desktop.
Find and replace in JARs
#!/bin/sh
# From within a (bash) script you need to use double quotes instead of singel qoutes to expand the variable
newAddress="org.springframework.cloud.contract.verifier.dsl"
oldAddress="org.springframework.cloud.contract.spec"
repo="$HOME/repo/accurest"
currentDir=`pwd`
cd $repo
for fname in $(find "$repo" -regex '.*/src/test/resources/m2repo/.*.jar')
do
echo "Found $fname"
zipgrep -q $oldAddress $fname;
result=$?
echo "Result $result"
if [ $? -eq 0 ]; then
echo "Changing $fname since it matches the pattern"
filename="${fname%.*}"
unzip -qp $fname | sed -e 's#'$oldAddress'#'$newAddress'#g' > $filename
zip $filename.jar $filename
echo "Changed $fname's contents"
fi
done
cd $currentDir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment