Split file based on the number of X symbol on each line

I'm not sure if this is possible, but I'm wondering if it'd be able to split a file into multiple files - dependent on the amount of a specified character there is on each line.

Lets use a colon (:) as an example

File.txt contains the following data (example):

Stack:Overflow   
Stack:Overflow:Flow    
Stack:Over:Flow:Com

Entire line containing 1 colon, goes to 1.txt
Entire line containing 2 colons, goes to 2.txt
Entire line containing 3 colons, goes to 3.txt

(And of course) there wouldn't be a limit to the amount of colons, and format may not necessarily always match the exampled pattern.

Sorry if this is a vague question, I'm first time posting on StackOverflow in a long.


Another side question: Inserting a specific character between 2 different regexs.

Data:

Stack@Stack.Stack192.168.0.1

I'm trying to insert a delimiter which will be ":"
Between 2 different regexes.
Regex #1 being: [A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}
Regex #2 being: [0-9]{1,4}\.[0-9]{1,4}\.[0-9]{1,4}\.[0-9]{1,4}

So the desired output would be:

Stack@Stack.Stack:192.168.0.1


Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)