Solved

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

Posted on 2016-10-24
10
118 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 4

Accepted Solution

by:
Abhimanyu Suri earned 250 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 125 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 125 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

A brief introduction to what I consider to be the best editor for PowerShell.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

738 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