Re: Split file by contents



On Wed, 27 Sep 2006 08:51:27 -0700, howa wrote for everyone to trash:


Davide Bianchi

On 2006-09-27, howa <howachen@xxxxxxxxx> wrote:
how to split a large XML file without a XML parser (since a few GB
data)

use ed:

ed - -s yourfilenamehere <<EOF > /dev/null 1
/^<book>$/
.,/^<\/book>$/w newfilenamehere
q
EOF

man ed for more info
Note: not tested.

Davide

--
Security-wise, NT is a server with a "Kick me" sign taped to it. --Peter
Gutmann

Hello, as my file is very large, so use of `sed` is better ?

Sed would work. Man sed,
http://www.cornerstonemag.com/sed/

$ sed -f/home/programs/sedfileused.ans /home/file-used

# sedfileused.ans
# sed script to delete a block if /regex/ matches inside it
:t
/\<book\/,/\/\<boo\>/ {
# For each line between these block markers..
/\<book\>/!{ # If we are not at the /end/ marker
$!{ # nor the last line of the file,
N; # add the Next line to the pattern space bt
} # and branch (loop back) to the :t label.
} # This line matches the /end/ marker.
/matched/d; # If /regex/ matches, delete the block.
} # Otherwise, the block will be printed.
#---end of script---



.