Exclude delimiter with csplit
Since you seem to be using gnu csplit
, it's quite simple:
csplit --suppress-matched infile /PATTERN/ '{*}'
i.e. use --suppress-matched
to suppress the lines matching PATTERN
.
Per your note, this option is available only with more recent versions of csplit
(coreutils
≥ 8.22)
perl -ne 'BEGIN { $fnum=0; open $fh, ">", sprintf "xx%02d", $fnum++ } if (m/-/) { open $fh, ">", sprintf "xx%02d", $fnum++ } else { print $fh $_ }' inputfileorfileshere
Or a similar reopen-into-new-file-on-matching-appropriate-line via awk
or whatever.
If you can make do with a string match rather than a regex match
awk 'BEGIN {RS="---\n"; ORS=""} {print > sprintf("xx%02d", NR)}' in
With GNU awk (at least in v4.0.1) it is possible to use a regex for RS
e.g.
gawk 'BEGIN {RS="-+\n"; ORS=""} {print > sprintf("xx%02d", NR)}' in