Question

I have this .xml file:

<docs>
<doc>
Some text
</doc>
<doc>
here some
</doc>
<doc>
text here
</doc>
</docs>

I am trying to use csplit in order to get only the text parts. This is what I came up with.

$ csplit docs.xml '%^<docs>%1' '/^<\/doc/1' '{*}'
Was it helpful?

Solution

if the file structure like the one you included you can extract the content by doing grep -v "^<" x or more conveniant approach cat x|sed -e 's/<[^>]*>//g'|grep -v '^$' or to do it the csplit way based on the comments below you can do it lik this

cat doc.xml | egrep -v '<?xml version="1.0" \?>|<docs>|</docs>' | csplit -q -z - '/<doc/' '{*}' --prefix=out-
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top