This is an almost identical question to split file into two parts, at a pattern but instead of having the lines up to XYZ in file1
in the example file.txt
:
ABC
EFG
XYZ
HIJ
KNL
I want to have the XYZ included in file2
(but XYZ
is still the pattern to divide on). What I have now is using this answer: https://unix.stackexchange.com/a/202516/108861 and then adding the last line from file1
to the top of file2
and removing it from file1
, but is there an easier one-line solution?
csplit
splits up to but not including the pattern. – don_crissti Sep 08 '15 at 14:26csplit
with the/pattern/
regexp form ("copy up to but not including a matching line"), so you should be able to use this answer from the question you linked, simply omitting the+1
offset. – steeldriver Sep 08 '15 at 14:26