Hi, I have the following input:
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
…
I want to transform this to:
Line 1: Line 2
Line 3: Line 4
Line 5: Line 6
Line 7: Line 8
…
How can I archive this? Thanks!
Hi, I have the following input:
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
…
I want to transform this to:
Line 1: Line 2
Line 3: Line 4
Line 5: Line 6
Line 7: Line 8
…
How can I archive this? Thanks!
How about this? Note - make sure you copy your input text into the clipboard before running the macro.
Download Macro(s): Test Combine Lines.kmmacros (6.5 KB)
As an alternative to @tiffle's method, you can also do it directly with a Regular Expression "Search and Replace". So to transform text on the clipboard:
Search: (.+)\R(.+\R?)
Replace: \1%Space%\2
I have the following input ... I want to transform this to ... how can I achieve this ?
I think this wins a prize for the best-asked question I have seen for a long time ...
( and quickly reaped a good harvest of responses ...)
Doesn't that just double each line, :
separating the items?
Thanks ! Reading too fast.
This problem is very straightforward, and there are all sorts of methods of getting it done.
I'd normally do this sort of job with RegEx but thought I'd stretch my legs a little and get some practice in with other tools.
(And – @Nige_S beat me to the RegEx anyway ).
Sed Version
Download: Concatenate Every Other Line of Data String (Sed) v1.00.kmmacros (6.8 KB)
Awk Version
Download: Concatenate Every Other Line of Data String (Awk) v1.00.kmmacros (6.8 KB)
Perl Version
Download: Concatenate Every Other Line of Data String (Perl) v1.00.kmmacros (6.8 KB)
JavaScript Version
Download: Concatenate Every Other Line of Data String (JavaScript) v1.00.kmmacros (7.6 KB)
Keyboard Maestro Native Version (Array)
** I used a different method than @tiffle's.
Download: Concatenate Every Other Line of Data String (KM Native Array) v1.01.kmmacros (9.2 KB)
Thank you for the multitude of solutions! (I‘ll use the regex, but it was helpful to see other possible solutions.)
If, incidentally, what was essentially needed was not so much the next line as the integer successor, e.g.
Line 1: Line 2
Line 202: Line 203
Line 7: Line 8
Line 4: Line 5
Line 501: Line 502
Line 6: Line 7
Line 788: Line 789
Line 8: Line 9
Then, of course, you could turn to a KM CALCULATE field or token, or a script:
I went with the RegEx because it handles a final half-line:
Line 1: Line 2
Line 3: Line 4
Line 5: Line 6
Line 7: Line 8
Line 9
...which may be out of scope, but you never know...
Turns out it wasn't that difficult to do the same with KM arrays:
Concat Test.kmmacros (6.1 KB)
I'm still dithering as to whether it's good practice to return similar transforms with a trailing newline when there wasn't one in the original string. Thoughts, anyone?
...is using the wrong increments. I think you need to create a Collection of "every odd integer between 1
and local_DataStr[0]
" and work from that.
Hi, @qrt. Here's one more using a native bash script:
Download: Concatenate Every Other Line of Data String (bash).kmmacros (6.0 KB)
Hey Nige,
Thanks for catching that!
I must have been seeing what I expected to see and not reality... My excuse is that it was late, and I was tired...
I used a single conditional to fix the problem and have replaced the original KM-Array version with v1.01
-Chris
Was thinking about it yesterday, and a fix that remains true to the spirit of your method would be to:
foreach from local_LineNum from 1 to (local_DataStr[0] / 2)
append local_newDataStr with local_DataStr[local_LineNum * 2 -1]:local_DataStr[local_LineNum * 2]\n
end