how to add a return after every tenth line

89 views
Skip to first unread message

Terry Collins

unread,
Feb 21, 2020, 3:26:00 PM2/21/20
to TextSoap
I have a large list of data that is in sets of 10 lines. I need to add a carriage return every tenth line. A line break would also suffice or maybe even be better. 
I am changing 9 of the returns to tabs but I need two returns after the 10th line

Can this be done? I am doing in manually now and it is tedious. I get these files every day and I can't keep up with getting them into a spread sheet. 

Mark Munz

unread,
Feb 21, 2020, 6:00:20 PM2/21/20
to TextSoap
Is the text in a continuous set of lines, ie:
line1
line2
line3
line4
line5
line6
line7
line8
line9
line10
line1
line2
line3
line4
..
?
Or are there breaks or anything I need to consider? 
If not, you can consider something like this for a custom cleaner:

Screen Shot 2020-02-21 at 2.50.13 PM.jpg

This takes 10 lines at a time and isolates them from the text. Once isolated, the fix is easy. Here's the breakdown:

If Text Matches - 
(?m) - this is equivalent to the m (Matches Lines) option being set.
^ - start at the beginning (of a line, when Matches Lines is set)
(.*?\n) - capture the contents of the entire line
{10} - and do it 10 times.
Match capture group : $0 - matches the entire group of lines

Now, all ten lines are in a single text unit.
Next, we find all \n (returns) and replace them with \t (tabs). This is equivalent to what you were doing for lines 1 - 9, but also does it at the end of line 10. We'll fix that next.
We use a regex find and replace \t$, but this time WITHOUT Matches Lines set. This matches a tab at the end of the text (remember, we are only working with the 10 lines with the If Text Matches, so it's effectively the tab on line 10). Then we replace that with \n\n, the two returns.

Again, I'm assuming that the text is all singe line with no breaks in between the records. If that's different, we can search for some other options.

Regards,
Mark Munz

--
You received this message because you are subscribed to the Google Groups "TextSoap" group.
To unsubscribe from this group and stop receiving emails from it, send an email to textsoap+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/textsoap/10af74ea-180f-4724-b299-7da90c783035%40googlegroups.com.


--
Mark Munz
unmarked software
http://www.unmarked.com/

Terry Collins

unread,
Feb 22, 2020, 2:18:22 PM2/22/20
to TextSoap
Thank you for helping me. 
If I select only ten lines at a time, this solution works. It makes two returns after the 10th line and a tab after the previous 9 lines
If I select the entire list it replaces all of the returns with single tabs. The list is of customer contacts so I can't post an example here. 

Any ideas?

Mark Munz

unread,
Feb 22, 2020, 2:30:37 PM2/22/20
to TextSoap
Without seeing the actual data (or some representation of that data), I'm just taking stabs in the dark.
Your options are:

1. Create a small subset of similar data that demonstrates the problem you described. You only need about 3-4 records maybe, change the names, email addresses, phone numbers, etc. That it what I tried to do with my example, but your data has something different that I cannot understand without knowing the type of data I'm looking at.

2. Write directly into support (at) unmarked.com, once a ticket is setup, you can attach some of the sample data as a text file (as little as is required to duplicate your issue). We treat any data sent to us as confidential and never share it or use it other than to solve your problem. Our goal is only to find a solution if possible, nothing more.

If you used some program to generate the data, it might be helpful to know the details of that. Perhaps there is a clue in how the data is written out and might point to a more general solution.

Note: If the solution remains more general, I may also post the SOLUTION (custom cleaner) without any data so people can learn from it, but again, the data never gets shared.

Mark


--
You received this message because you are subscribed to the Google Groups "TextSoap" group.
To unsubscribe from this group and stop receiving emails from it, send an email to textsoap+u...@googlegroups.com.

Terry Collins

unread,
Feb 24, 2020, 12:20:48 PM2/24/20
to TextSoap
This is how I get the list. These are the fields. 

Name

Email
Phone
Subject
Email Template Name
Date Sent
Date Opened
Last Opened
Opened?
Name
Email
Phone
Subject
Email Template Name
Date Sent
Date Opened
Last Opened
Opened?
Name
Email
Phone
Subject
Email Template Name
Date Sent
Date Opened
Last Opened
Opened?
Name
Email
Phone
Subject
Email Template Name
Date Sent
Date Opened
Last Opened
Opened?
# Times Opened↓
To unsubscribe from this group and stop receiving emails from it, send an email to text...@googlegroups.com.

Mark Munz

unread,
Feb 26, 2020, 11:03:11 AM2/26/20
to TextSoap
OK, There are two ways to solve this with TextSoap 8.
1. Create three separate cleaners and apply two of them as necessary.

Custom Cleaner 1: Collect 1 Record
Screen Shot 2020-02-26 at 7.47.14 AM.jpg

Custom Cleaner 2: Collect Multiple Records
Screen Shot 2020-02-26 at 7.47.23 AM.jpg

Custom Cleaner 3: Finish Record Processing
Screen Shot 2020-02-26 at 7.47.31 AM.jpg

What you do then, is apply Collect Multiple Records until all the records are processed.
You can add more "Apply: Collect 1 Record" actions to multiply the processing amount per pass.

What happens here is that Collect 1 Record will process text from the beginning of text. It will then grab the 9 fields, convert the returns to tabs and then (the magic here) it takes the end of this "record" and adds a marker "X1X1X1" (this can be anything as long as it is unique to the text and matches whatever is in Finish Record Processing). This leaves everything prior on the first line of text. You can then repeatedly apply this cleaner to process more records.

Note: if you have a LOT of records, it may be beneficial to manually split the text into chunks to boost performance.

Finally, when you've processed all the records, you just need to convert the X1X1X1 marker back to \n (I just realized you wanted \n\n, but you can do that too). Now all your records are processed.

Because it is removing all returns and repeatedly searching through the text, if you have a tone of records, it may take a while. A better option is to break large text into smaller chunks and process it.

In the future, this might be simplified. 🙂

In the 2nd post, I'll show how do to this within a single cleaner using Macros. The only change is how many times you call the macro.

To unsubscribe from this group and stop receiving emails from it, send an email to textsoap+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/textsoap/52781d5c-6e4e-48f1-b183-e0755c54f332%40googlegroups.com.

Mark Munz

unread,
Feb 26, 2020, 11:09:15 AM2/26/20
to TextSoap
2. You can create a single cleaner which incorporates the previous 3 cleaners into a single one.

Screen Shot 2020-02-26 at 8.04.25 AM.jpg
Here, we add a "Define Macro" action called "Collect 1 Record". It contains the same actions that were in the 1st custom cleaner we created before. Once defined, you can hide the actions to free up space.

Next, we Apply the Macro. This is similar to Apply Cleaner, except it does it using the definition you setup earlier. In this example, it only calls it three times, but you can add more to process more records.

Finally, the last action converts all the markers created to returns (just like the Finish Processing Records" cleaner).

Depending on the scale of the text you are processing, you may want to choose a single cleaner or action or go with the multiple cleaner action defined earlier.

terry collins

unread,
Feb 26, 2020, 2:06:01 PM2/26/20
to text...@googlegroups.com
Thank you for this. I don’t understand how to create the second cleaner. 
Which function should I use or search for among all the cleaners to do the Apply: Collect 1 Record?



On Feb 26, 2020, at 11:02 AM, Mark Munz <unma...@gmail.com> wrote:

OK, There are two ways to solve this with TextSoap 8.
1. Create three separate cleaners and apply two of them as necessary.

Custom Cleaner 1: Collect 1 Record
<Screen Shot 2020-02-26 at 7.47.14 AM.jpg>

Custom Cleaner 2: Collect Multiple Records
<Screen Shot 2020-02-26 at 7.47.23 AM.jpg>

Custom Cleaner 3: Finish Record Processing

Mark Munz

unread,
Feb 26, 2020, 2:11:03 PM2/26/20
to TextSoap
To create the 2nd and 3rd cleaners, click the "Custom Cleaners & Groups" in the toolbar.
Then click the + button at the bottom and select "New Custom Cleaner".
Applying a cleaner is its own action. You can either
1. scroll to the bottom of the actions list
2. select Cleaners tab and scroll to bottom
3. type in "Collect 1 Record" in the filter field to display it.

Then double-click the action to add it to your current custom cleaner.

goldto...@gmail.com

unread,
Jul 25, 2023, 1:43:05 PM7/25/23
to TextSoap
I updated to the newest version and want to get back to this project. I am having no luck. 
This is how the file is formatted. I've tried the cleaner you showed as an example to no avail.

Mark Munz

unread,
Jul 27, 2023, 1:50:55 PM7/27/23
to text...@googlegroups.com
You can use something like this:

image.png





--
Mark Munz
unmarked software
https://textsoap.com/

Reply all
Reply to author
Forward
0 new messages