Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

looking for unix program to search some keywords in side EAR WAR and JAR files

Posted on 2016-10-24
10
Medium Priority
?
140 Views
Last Modified: 2016-11-09
Hi,

I am looking for unix program to search some keywords(say "hello", "world" etc) in side EAR file (say xyz.EAR) which has a  WAR file(say abc.war) and has JAR files(like def.jar, ghi.jar).

I have installed cygwin and MobaXTerm already. Please advise
0
Comment
Question by:gudii9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 5

Accepted Solution

by:
Abhimanyu Suri earned 1000 total points
ID: 41857767
Here is an example of egrep

/home/TEST>ls -ltrR
.:
total 20
-rw-r--r-- 1 oracle oinstall    6 Oct 24 18:03 abc
drwxr-xr-x 3 oracle oinstall 8192 Oct 24 18:05 TEST1

./TEST1:
total 28
-rw-r--r-- 1 oracle oinstall    6 Oct 24 18:04 def
-rw-r--r-- 1 oracle oinstall    6 Oct 24 18:04 ghi
-rw-r--r-- 1 oracle oinstall    6 Oct 24 18:05 klm
drwxr-xr-x 2 oracle oinstall 8192 Oct 24 18:06 TEST2

./TEST1/TEST2:
total 4
-rw-r--r-- 1 oracle oinstall 7 Oct 24 18:06 nop


/home/TEST/TEST1/TEST2>cat nop

hello
/home/TEST/TEST1/TEST2>cd ..
/home/TEST/TEST1>ls -ltrh
total 28K
-rw-r--r-- 1 oracle oinstall    6 Oct 24 18:04 def
-rw-r--r-- 1 oracle oinstall    6 Oct 24 18:04 ghi
-rw-r--r-- 1 oracle oinstall    6 Oct 24 18:05 klm
drwxr-xr-x 2 oracle oinstall 8.0K Oct 24 18:06 TEST2
/home/TEST/TEST1>cat def
hello
/home/TEST/TEST1>cat ghi
world
/home/TEST/TEST1>cat klm
world
/home/TEST/TEST1>cd ..
/home/TEST>ls -ltr
total 20
-rw-r--r-- 1 oracle oinstall    6 Oct 24 18:03 abc
drwxr-xr-x 3 oracle oinstall 8192 Oct 24 18:05 TEST1
/home/TEST>cat abc
hello
/home/TEST>
/home/TEST>

/home/TEST>egrep -iR "hello|world" ./*
./abc:hello
./TEST1/TEST2/nop:hello
./TEST1/def:hello
./TEST1/ghi:world
./TEST1/klm:world
/home/TEST>
0
 
LVL 16

Assisted Solution

by:Hanno P.S.
Hanno P.S. earned 500 total points
ID: 41858417
a) "strings" will display all readable strings in any give file
strings def | grep -i world

Open in new window

b) an WAR or JAR is nothing else but a (slightly modified) tar archive
tar xvf - def.jar | grep -i hello

Open in new window

Does this help?
0
 
LVL 7

Author Comment

by:gudii9
ID: 41858623
any sample shell script for this?
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 500 total points
ID: 41858632
jars are (almost always) collections of zip encoded files in an archive. As such, strings like 'hello' may not be detectable, even if they are in one of the files compressed in the archive. Of course nesting jars raises the bar even higher
0
 
LVL 16

Expert Comment

by:Hanno P.S.
ID: 41858680
If the file in the jars are compressed (in which way ever) the only way
would be to unpack the archives (hierarchally where needed) and
scan the resulting diretory tree afterwards
To give you some idea: Scan all files in current directory tree, try something like
cd <top-level-directory>
strings `find * -type f` | grep -i hello 

Open in new window

0
 
LVL 7

Author Comment

by:gudii9
ID: 41858686
how to search multiple words about 100 same time and generate some text report? any sample shell script to this. if i search hello it should not find helloall as well.  Needs to be correct match
0
 
LVL 16

Expert Comment

by:Hanno P.S.
ID: 41858731
Use grep in the right way no NOT match helloxyz, only hello as a single word
Something like:
grep -i '[ ^]hello[$ ]'

Open in new window

Read how to use (and compose) regular expresiions for grep to accomplish this.

To put all this into a file:
strings `find * -type f` | grep -i hello > report.txt 2>&1 

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 41858796
Using Perl regex (depending on what version of grep you have) is easier

grep -iP '\bhello\b'

Open in new window

0
 
LVL 16

Expert Comment

by:Hanno P.S.
ID: 41858836
... as you say "depending on grep version".
Your man page(s) for grep should shed light on this.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 41880885
Sorry - how does the 'Accepted Solution' answer the question in any way?
0

Featured Post

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question