While I appreciate the desire to have a solution that uses native Keyboard Maestro commands, when you're processing lines of text, it's hard to beat the old Unix tools. Printing out just one of many lines is the kind of thing sed was made for. For example, to print the 5th line of a file, do
And here's one that uses AppleScript. A benefit of this one is if you want the last line just specify -1; the next-to-last use -2, etc. (something that's also true of the KM variable array approach...)
Peter's solution works for the Nth last string in a series of strings on a single line (usually the comma is the delimiter) but if you want KM to give you the Nth last line in a multi-line variable, without resorting to external scripts, you can do it this way:
This is a variation of the solution I posted above for finding the Nth line. But when counting backwards like this, you have to be careful that the last line of your file ends with a newline, or you might miss your desired line by one. I suppose you could account for that by changing this action.
I should have posted the macro in this thread. But since I've deleted it, I'll retype the important line for everyone here:
Cool! You might try and document your progress, so you can share it with others. On the other hand, maybe just learning regex is enough of an effort, just by itself.
Yes, and I’ve learned more about KM lists from this thread than I ever knew before.
On the other hand, I was looking for a one-action, one-line solution. Until you get the \n syntax working, KM still requires a find/replace action first.
Great. It often seems to be the case that Variables are multi-line and being able to directly reference those lines like this will simplify things a lot. Thank you!