1

I want to split a file after a delimiter, not before the delimiter, which is what csplit does. I can't find anything anywhere! (Also, why would there be a tool that specifically splits before a pattern, but not one that splits after it?)

File:
a
b
c
d

split at c

output: file1:
a
b
c

file 2
d

12
  • 1
    "I can't find anything anywhere!" Where exactly are you searching ? csplit, like all tools, has manual page. That's the first place to search - usually, the man page contains the answer... Apr 26, 2018 at 13:33
  • It does not, it only shows how to split before a pattern... @don_crissti
    – LizzAlice
    Apr 26, 2018 at 13:34
  • What's your csplit version ? Apr 26, 2018 at 13:35
  • 4
    yeah, it's /REGEXP/[OFFSET] and if you read further it says A line OFFSET is a required '+' or '-' followed by a positive integer. Apr 26, 2018 at 13:45
  • 1
    just csplit file.txt /c/+1 - that's all Apr 26, 2018 at 13:48

1 Answer 1

2

The syntax is /REGEXP/[OFFSET]. So given

$ cat file
a
b
c
d

then

$ csplit file '/^c/+1'
6
2

gives

$ head xx*
==> xx00 <==
a
b
c

==> xx01 <==
d

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .