shellcsplit

shell : csplit command


i'am trying to use csplit command on a file of 700 Mo. I would like to split the file into 30 smallers files and also respect the tag name i use to start a new file.

<head>
 <test>1 </test>
</head>

<head>
 <test>2 </test>
</head>

<head>
 <test>3 </test>
</head>
...
<head>
 <test> 80 </test>
 </head>

Suppose i have 80 groups tags so i would like to generate exactly 30 files. So how can i do it using csplit. The begining i know is

csplit output_prefix File '/<head>/' '{*}'

Solution

  • Discovering csplit is half the battle! This should work:

    % csplit --prefix File --elide-empty-files foo.xml '/<head>/' '{*}'
    33
    33
    ...
    
    % ls
    File00  File01  File02  ...  foo.xml
    

    The option/argument order is important. Try csplit --help to see all of its options.

    % csplit --help
    Usage: csplit [OPTION]... FILE PATTERN...