Searching the value of a specific attribute among xmls files from a particular directory location

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Searching the value of a specific attribute among xmls files from a particular directory location
# 1  
Old 06-19-2016
Wrench Searching the value of a specific attribute among xmls files from a particular directory location

Hi Folks ,

I have the different xml files at the following directory `/opt/app/rty/servers/tr/current/ops/config`

Let's say there are three files named

Code:
    abc.xml
    bv.xml
    ert.xml



Now inside these xml there can be many tags as like shown below

Code:
   <bean id="sdrt" class="com.interfaces.send.erty">                    
        <property name="eprocDependentOnClientAddress"><value>@argon.tdw.client.address@</value></property>
        <property name="eprocDependentOnClientAddressEod"><value>tyu</value></property>                    
    </bean>

Now my objective is that inside directory /opt/app/rty/servers/tr/current/ops/config I need to search in all xml files and have to find that in every xml in context to property tag there should be no value starting from @ tag and also ending with @ tag


Let's say for example in the above xml file the below is correct

Code:
   <property name="eprocDependentOnClientAddressEod"><value>tyu</value></property>

but the below is not correct

Code:
   <property name="eprocDependentOnClientAddress"><value>@argon.tdw.client.address@</value></property>


so please advise what will be the single command in unix to search the files names that is those xml in which there is a tag starting with @ inside the property tag , There must be a command starting with egrep..Smilie

Last edited by Scrutinizer; 06-19-2016 at 02:49 AM.. Reason: quote tags -> code tags
# 2  
Old 06-19-2016
A simple approach would be:
Code:
grep '<property.*<value>[^@].*[^@]</value></property>' file

But that assumes every property is neatly on one line.
# 3  
Old 06-19-2016
Quote:
Originally Posted by Scrutinizer
A simple approach would be:
Code:
grep '<property.*<value>[^@].*[^@]</value></property>' file

But that assumes every property is neatly on one line.
Thanks but when i executed this as in this fashion below
Code:
grep '<property.*<value>[^@].*[^@]</value></property>' *.xml

well it searches among all xml's which is OK but it bring out the all the value tags but i am looking for the tags like as shown below only

Code:
<property name="eprocDependentOnClientAddress"><value>@argon.tdw.client.address@</value></property>

so as you can observe the output should be only the tags in which from within the value tag the value is staring from @ tag and ending with @ tag only , please advise how to achieve thisSmilie
# 4  
Old 06-19-2016
Would replacing either of the two occurrences of [^@] with just @ cure the problem?
# 5  
Old 06-19-2016
Like RudiC says, if are looking for the opposite, then you get those lines that contain the @ characters in the value part.

To get only the file names with the wrong value tags, try the -l option:
Code:
grep -l '<property.*<value>@.*@</value></property>' file(s)

# 6  
Old 06-19-2016
Thanks but it is still not working , please advise can it be like this as I have shown below since outside there is a bean tag inside there is a property tag and inside that there is value tag . please advise

Code:
grep -l '<bean.*<property.*<value>@.*@</value></property></bean>' *.xml

# 7  
Old 06-19-2016
Please be more precise: WHAT is "still not working"? Post input, commands and results and tell us what and why doesn't meet your needs.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to find a existing file location and directory location in Solaris box?

Hi This is my third past and very impressed with previous post replies Hoping the same for below query How to find a existing file location and directory location in solaris box (1 Reply)
Discussion started by: buzzme
1 Replies

2. Red Hat

Moving of file content to another two files after searching with specific pattern

Hello, Please help me with this!! Thanks in advance!! I have a file named file.gc with the content: 1-- Mon Sep 10 08:53:09 CDT 2012 2revoke connect from FR2261; 3delete from mkt_allow where grantee = 'FR2261'; 4grant connect to FR2261 with '******'; 5alter user FR2261 comment... (0 Replies)
Discussion started by: raosr020
0 Replies

3. Shell Programming and Scripting

Searching for files with specific extensions

Hi, Could someone give me a hand with a search for files with two possible extensions, please. The requirement is simple - I need to issue a single ls command searching for files with the suffix of, say, *.txt and *.log. I've tried to use ls *.txt *.log which works if there are both... (4 Replies)
Discussion started by: neilmw
4 Replies

4. Shell Programming and Scripting

Updating the files at specific location

Hi All, I have a requirement wherein I need to test if a line in file succeeding "IF" statement has "{" .If the line succeeding "IF" statement does not have "{" , then I need to insert the "{". Similarly , I need to check if a line in file preceding "ENDIF" statement has "}" .If not , then I... (2 Replies)
Discussion started by: swapnil.nawale
2 Replies

5. UNIX for Advanced & Expert Users

How to perform Grep on many Gzip files, Searching for Specific information

Hello, I am wondering if you can assist with my question and ask kindly for this. I have a number of files that are listed as file1.gz through file100.gz. I am trying to perform a grep on the files and find a specific date that only resides within within one of the files. There are... (3 Replies)
Discussion started by: legharb
3 Replies

6. Solaris

Searching for files in a Directory

Hi, I am trying to write a script that will search in a particular directory and tell me how many files are in there. I then want to be able to email certain users of how many files are in that directory and what the file names are? any help would be great as i am getting confused. thanks (3 Replies)
Discussion started by: Pablo_beezo
3 Replies

7. UNIX for Dummies Questions & Answers

searching files inside directory

hey, i need to use grep to search a bunch of header files inside a directory to return which file i can find the function i'm searching for in. how do i use wild cards to search through the files? i can only figure out how to search inside the directory, not inside the files that are in the... (4 Replies)
Discussion started by: kylethesir
4 Replies

8. Shell Programming and Scripting

Searching files in a directory.Urgent

Hi everyone, I need to search files starting with RPT_0, RPT_1,........ in a directory. How can I implement that through a shell script. Also I want to read the last line of each file after searching them. Can someone help me out in this regard. One more thing how I can extract a particular... (7 Replies)
Discussion started by: srivsn
7 Replies

9. UNIX for Dummies Questions & Answers

searching text files on specific columns for duplicates

Is it possible to search through a large file full of rows and columns of text and retrieve only the rows that contain duplicates fields, searchiing for duplicates on col4 & col6 Sample below Col1 col2 col3 col4 col5 col6 G405H SURG FERGUSON ... (2 Replies)
Discussion started by: Gerry405
2 Replies
Login or Register to Ask a Question