csplit: detecting pattern in a line

hy9fesh

New Member
Joined
Jul 30, 2020
Messages
1
Reaction score
0
Credits
13
I have a file that looks something like this:

CBA ABC
line 1
line 2
DFCF ABC
line 1
line 2

I want to split the file into two separate files that look like this:

File 1

CBA ABC
line 1
line 2

File 2

DFCF ABC
line 1
line 2

I'm using the following code:

Code:
for filename in *.txt; gcsplit -z -f "${filename%.*}_" --suffix-format="%d.txt" $filename '/ABC/ ' '{*}'

But since ABC does not come first in any of the lines, the code is unable to detect it.

How do I get the files to split whenever "ABC" appears in a line?
 

Members online


Top