tags:

views:

37

answers:

2

How do I search for anything between these tags, I would like to list all occurences where there is some value between the f:facet xml element

<f:facet name="header">Name</f:facet>
+1  A: 

if every f:facet tag is on a separate line then you can do like this:

cat file.xml | sed -ne 's/<f:facet[^>]*>//;s/<\/f:facet>//p'|grep Name

if you want to look across multiple files you can do:

find . -type f| xargs sed -ne 's/<f:facet[^>]*>//;s/<\/f:facet>//p'
catwalk
apologize if I was not clear, I would like to do a blanket search across all files which could contain any text (not just name) between the facet elements
Samuel
@Samuel: see updates to my answer
catwalk
I get the following error message, not sure what I am missing here. sed, find, xargs are getting picked up from the cygwin installation on my Windows machine.c:\>find . -type f| xargs sed -ne 's/<f:facet[^>]*>//;s/<\/f:facet>//p'The specified path is invalid.
Samuel
@Samuel: you have to use double quotes on windows instead of single quotes
catwalk
double quotes fixed all the issues, thanks
Samuel
+1  A: 

This will list whatever occurs between the <f:facet> tags:

sed 's/<f:facet[^>]*>\([^<]*\)<\/f:facet>/\1/'

This test:

echo '<f:facet name="header">Name</f:facet>' | sed 's/<f:facet[^>]*>\([^<]*\)<\/f:facet>/\1/'

Outputs this:

Name

To run it on all files in the current directory:

sed 's/<f:facet[^>]*>\([^<]*\)<\/f:facet>/\1/' *

To run it on all files in all directories under a common one:

find /path/to/common -type f -print0 | xargs -0 sed 's/<f:facet[^>]*>\([^<]*\)<\/f:facet>/\1/'

If you're running find from a Windows CMD.EXE prompt, you're probably getting the Windows FIND.EXE which is giving you that error message. Try find --help and find /?. The former is GNU find and the latter is Windows. If the former gives you an error message and the latter gives you help text, then that will confirm the problem.

You will need to start an instance of Cygwin instead.

Dennis Williamson
thanks, there was an issue between the find program in windows / cygwin
Samuel