Page 1 of 1

split lines according to condition

Posted: Fri Mar 04, 2011 9:44 am
by mixtape
Hi,

I want to split a line after a certain number of ["].

How to i do this?

Thanks in advance!

//A.

Posted: Fri Mar 04, 2011 9:56 am
by ben_josephs
Do you want to insert a newline into each line after its nth double quote symbol, for some n?

If so, and if, say, n = 6, try:

Use "Posix" regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
Search | Replace... (<F8>):
Find what: ^([^"]*"){6}
Replace with: \0\n

[X] Regular expression

Replace All

Posted: Fri Mar 04, 2011 1:04 pm
by mixtape
Thanks!

But i might have done this the wrong way... see i have some rows that are separated with [enter] when they're not suppose to.

So can i do a search and replace looking for n number of symbols and then replace the [enter] with nothing?

Thanks again!

Posted: Fri Mar 04, 2011 2:14 pm
by ben_josephs
Do you mean that some newlines are added that you don't want?

Please explain precisely, with examples, where my suggestion works as you want it to and where it doesn't.

Posted: Fri Mar 04, 2011 2:21 pm
by mixtape
Sorry about that. The problem was, since i had rows where there were not suppose to be an [enter] i thought that maybe if i remove all the [enters] including the onces at the end of every row where they're suppose to be and then separate that long one line every number of symbols that i desired.

Problem with that was that the line were over 33 milj characters long. not popular.

so this is how it looks;

ROW 1 "field1";"field2";"field3";"field4" [enter] <--- ok enter
ROW 2 "field1";"field2";"field3";"[enter] <---not ok enter
"field3";"field4"; [enter] <--- ok enter
ROW 3 [....]

is this understandable?

//A.

Posted: Fri Mar 04, 2011 3:21 pm
by ben_josephs
Just tell us where you want the newlines and where you don't. Give examples of text before and after the change.

Posted: Fri Mar 04, 2011 3:26 pm
by mixtape
This is how it is now

"field1";"field2";"field3";"field4";"field5"[enter]
;"field6"[enter]

This is how i want it;

"field1";"field2";"field3";"field4";"field5";"field6"[enter]

//A.

Posted: Sat Mar 05, 2011 4:42 pm
by ben_josephs
You really are not being clear. Do you mean that you want a newline after every (say) twelfth double quote symbol, regardless of where the newlines are initially?

If so you might do this in two steps:

1. Insert a newline after every second double quote symbol if there isn't already one there:
Find what: (([^"]*"){2})(.)
Replace with: \1\n\3

[X] Regular expression

Replace All
2. Remove every sixth newline:
Find what: (.+)\n(.+)\n(.+)\n(.+)\n(.+)\n(.+)
Replace with: \1\2\3\4\5\6

[X] Regular expression

Replace All
These assume you are using "Posix" regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
If this is not what you want, you will have to explain your requirements more clearly.

Posted: Mon Mar 07, 2011 7:28 am
by mixtape
Ok. I'll try to explain it in another way, thanks for being patient by the way.

I have a set of data that contains say 20 fields (columns) on every row. Every row is separated with an "enter"

But, some of the rows are splitted after only the 10th field having the other 10 fields (on that supposed row), continuing on the next row. So that row has to "enters" instead of one.

Now, what i want to do is remove the "split" so that the row of the 20 fields are intact again. hence, remove the enter after the 10th field.

fields, like i said before are quoted with " and separated with ;

Posted: Mon Mar 07, 2011 9:14 am
by ben_josephs
That is entirely different from what you asked for initially.

Do all the continuation lines begin with a semicolon? If so, try
Find what: \n;
Replace with: ;

[X] Regular expression

Replace All

Posted: Mon Mar 07, 2011 9:29 am
by mixtape
No but it starts with ";"

So thanks alot! This worked like charm! You are a lifesaver!

Thank you!