user2197116
user2197116

Reputation: 677

How do I pipe grep xmllint results?

Trying to use xmllint to validate a bunch of XMLs.

I use the command: xmllint --noout --schema MySchema.xsd dir/*.xml

This prints to stdout a list of each file and whether it validated or failed. I wish to prune this list and show only those files which failed to validate.

I'm used to being able to do a pipe grep on stdout to filter the results. For example, if I do ls | grep "config" it will list only those files with config in the name.

But for some reason doing the above command followed by | grep "fails" or | grep -v "validates" has no effect whatsoever on reducing the (massive) number of lines of text thrown into the console stdout. The full list is presented regardless

It's almost as though output from xmllint is not valid input for the pipe.

Upvotes: 1

Views: 2580

Answers (1)

Uku Loskit
Uku Loskit

Reputation: 42030

xmllint is probably printing to stderr instead of stdout. Redirect your stderr to stdout before the grep.

xmllint --noout --schema MySchema.xsd dir/*.xml 2>&1 | grep -v "validates

Upvotes: 4

Related Questions