Skip to main content
Bash isn’t a text editor
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 265
Source Link

Bash Split into files by line

I have a huge .txt file with multiple lines, but there's a particular string on a line that separates a number of lines from one another

I want to use that string to split into numerous files named the current string.

Example of specific string:

 Found matches in (anything can be here):

Example of data in huge .txt:

 Found matches in (anything can be here):
 ..............
 ..............
 ..............
 ..............
 ..............
 ..............

 Found matches in EXAMPLE:
 ..............
 ..............
 ..............
 ..............
 ..............
 ..............

Desired output:

 Found matches in (anything can be here).txt < contains data below its self but before another line stating " Found matches in

 Found matches in EXAMPLE.txt < contains data below its self but before another line stating " Found matches in

Also it's possible that there could be duplicate " Found matches in (anything can be here)" lines with data, so rather than overwrite the current, is it possible to rename (1) and (2) and (3) etc or just simply ADD too the current file ( not overwrite)