How to grep multiple pattern from XML file

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to grep multiple pattern from XML file
# 1  
Old 04-07-2010
Error How to grep multiple pattern from XML file

Hi Everyone
pls if anyone can help me in writing a script or correcting it what I have done.

I want to write a script to grep record number for all those record which have abc xyd cat dog in one of the field say VALUE, I have thousand of file in a dir and I want to search every file for mathching pattern in field VALUE ,I was trying to give path of dir from command prompt.
for i in `ls $filepath`
  for y in `grep -il patternfile $filepath$i`
    echo "processing file $y"
    egrep "<RecordNumber>" $y >>metafile.txt


Last edited by Franklin52; 04-07-2010 at 04:17 AM.. Reason: Please indent your code and use code tags!
# 2  
Old 04-07-2010
What is the error you face in this ?

Or what stops you from achieving wht you require ?
# 3  
Old 04-07-2010
Network The error I am Getting

My script is not searching in every file in a dir for the multiple pattern which I have saved to a pattern file. Is there a another way to solve the problem . I think I am doing something wrong in looping . It is not searching everyfile in a dir.
pls help me if anyone solve this or figure it out.

# 4  
Old 04-07-2010
correct the capital P in filePath in line 2

put a / between $filepath and $i in line 5 - unless you always give param 1 with a trailing /

You could also try ls -1 to make sure the filenames come out on separate lines.
# 5  
Old 04-07-2010
You need to find those files which include something and if include then find some other line ?

You can use filegeneration, no need to use ls.

But in this case, you can use grep, no need to make fileloop.
grep -il "VALUE"  $filepath/* | while read file
    grep "<RecordNumber>" $file >>metafile.txt

If you need also files begin ., then something like
grep ... $filepath/* $filepath/.[!.]*  | ...

If you need more rule (=OR)
grep -il -e "pattern1" -e "pattern2"
or write rule to the file and then
grep -il -f patternfile ...

If you need AND patterns, then you need to pipe grep commands.

Example input data and example output data is the best method to tell us your real needs.

Last edited by kshji; 04-07-2010 at 12:16 PM..
# 6  
Old 04-07-2010
Network I want the record no for specific field where the pattern occur

Thanks all for replying back
my files(1000 of them ) in dir. My data lin file is ike this


I want to get all the record number for those record where <meta:term-source> is list, table, abc, photograph.

# 7  
Old 04-07-2010
Do you mean some thing like this:

awk '/<meta:term-source>/' * | egrep "list|table|abc|photograph"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to pull multiple XML tags from the same XML file in Shell.?

I'm searching for the names of a TV show in the XML file I've attached at the end of this post. What I'm trying to do now is pull out/list the data from each of the <SeriesName> tags throughout the document. Currently, I'm only able to get data the first instance of that XML field using the... (9 Replies)
Discussion started by: hungryd
9 Replies

2. UNIX for Beginners Questions & Answers

Grepping multiple XML tag results from XML file.

I want to write a one line script that outputs the result of multiple xml tags from a XML file. For example I have a XML file which has below XML tags in the file: <EMAIL>***</EMAIL> <CUSTOMER_ID>****</CUSTOMER_ID> <BRANDID>***</BRANDID> Now I want to grep the values of all these specified... (1 Reply)
Discussion started by: shubh752
1 Replies

3. UNIX for Advanced & Expert Users

Grep a pattern from zip file which has multiple files insdie

Hi Gurus, I got a small requirement in my script to grep a specific pattern in a zip compressed file which has been created with multiple files. Sample File: $> zipinfo -l 20180913_file1 20180913_file2 20180913_file3 20180912_file4 20180912_file5... (1 Reply)
Discussion started by: hi.villinda
1 Replies

4. Shell Programming and Scripting

Splitting a single xml file into multiple xml files

Hi, I'm having a xml file with multiple xml header. so i want to split the file into multiple files. Sample.xml consists multiple headers so how can we split these multiple headers into multiple files in unix. eg : <?xml version="1.0" encoding="UTF-8"?> <ml:individual... (3 Replies)
Discussion started by: Narendra921631
3 Replies

5. Shell Programming and Scripting

Split xml file into multiple xml based on letterID

Hi All, We need to split a large xml into multiple valid xml with same header(2lines) and footer(last line) for N number of letterId. In the example below we have first 2 lines as header and last line as footer.(They need to be in each split xml file) Header: <?xml version="1.0"... (5 Replies)
Discussion started by: vx04
5 Replies

6. Shell Programming and Scripting

Grep multiple pattern

I have got a text from each line, I need to fetch port only if there is an ip a.text text and port=25 b.ip=( and port="52" c.ip=( and port=25" d.text text and port="5" e.ip=( and port="457" f.ip=( and port="588" I know how to... (6 Replies)
Discussion started by: arpagon
6 Replies

7. Shell Programming and Scripting

Help required in Splitting a xml file into multiple and appending it in another .xml file

HI All, I have to split a xml file into multiple xml files and append it in another .xml file. for example below is a sample xml and using shell script i have to split it into three xml files and append all the three xmls in a .xml file. Can some one help plz. eg: <?xml version="1.0"?>... (4 Replies)
Discussion started by: ganesan kulasek
4 Replies

8. Shell Programming and Scripting

How to add the multiple lines of xml tags before a particular xml tag in a file

Hi All, I'm stuck with adding multiple lines(irrespective of line number) to a file before a particular xml tag. Please help me. <A>testing_Location</A> <value>LA</value> <zone>US</zone> <B>Region</B> <value>Russia</value> <zone>Washington</zone> <C>Country</C>... (0 Replies)
Discussion started by: mjavalkar
0 Replies

9. Shell Programming and Scripting

split XML file into multiple files based on pattern

Hello, I am using awk to split a file into multiple files using command: nawk '{ if ( $1 == "<process" ) { n=split($2, arr, "\""); file=arr } print > file }' processes.xml <process name="Process1.process"> ... (3 Replies)
Discussion started by: chiru_h
3 Replies

10. Shell Programming and Scripting

Help to search multiple pattern in file with grep/sed/awk

Hello All, I have a file which is having below type of data, Jul 19 2011 | 123456 Jul 19 2011 | 123456 Jul 20 2011 | 123456 Jul 20 2011 | 123456 Here I wanted to grep for date pattern as below, so that it should only grep "Jul 20" OR "Jul ... (9 Replies)
Discussion started by: gr8_usk
9 Replies
Login or Register to Ask a Question

Featured Tech Videos