searching contents of .class file within jar (for strings)
This may sound a bit odd, but at work we are having some difficulty figuring out what code is the culprit of printing to stdout. Our console is flooded with info lets say it's this:
System.out Tag read -> myTag System.out Tag name -> myName I want to be able to search in every jar, in every class file (they may be binary, but the strings will still be readable) to see if "Tag read" is in the .class file. For instance if it werent for jars I could do this: find -iname "*.class" -print0 | xargs -0 -n1 grep Tag\ read I don't know how to handle this when they are also jar'd up in an archive. find . -iname "*.jar" -print0 | xargs -0 -n1 ??what goes here?? It would be nice if I didn't actually have to extract files, but if I could specify a tmp location to extract to, so it doesn't muddy up the repository directories that would also be acceptable. |
Moin,
if you only want to know first, in which files the string appears, you can use the following sample (works only with GNU find!): Code:
find . -iname '*.jar' -printf "unzip -c %p | grep -q 'Tag read' && echo %p\n" | sh Jan EDIT: If you want to know, in which class within the archive the string appears, try this: Code:
find . -iname '*.jar' -print | while read jar; do |
wow I really wish I knew more about how this line worked because it works flawlessly and is disgustingly fast. It looks like you are printing a custom command out to the shell (sh). I understand everything except the %p. What command does %p belong to? Is it a built in shell variable? I realize its whatever is found by the find command.. but I'm very confused as to how it's ever stored there.
Also, does 'sh' always default to whatever shell is currently in use? |
Well I found out where the %p lives, I should have read the manual harder before jumping on here. (I thought typing '/%p' while in the man page would jump to it, but I guess not)
For anyone else reading this: %p is part of the -printf option within the find command. It will be resolved to the name of the file. Furthermore 'sh' is actually the command for the gnu bourne again shell, and here I thought it was 'bash'. Apparently you can run either? |
Moin,
Quote:
Code:
jan@jack:~/tmp> ls -li `which bash` Jan |
All times are GMT -5. The time now is 03:21 AM. |