Absolutely, but when what you want to achieve, you’ll have to think more, than with awk, I think you have seen a lot of examples of sed by now, for counting stuff and the like. You can also google for “sed Tower of Hanoi”.
For such a case as the above, a read command and some Applescript prepending each paragraph with the correct number would be faster, lest we not forget that.
property pp : ""
property nl : {}
set pp to "A WOLF who had a bone stuck in his throat hired a Crane, for a large sum, to put her head into his mouth and draw out the bone.
When the Crane had extracted the bone and demanded the promised payment, the Wolf, grinning and grinding his teeth, exclaimed:
"Why, you have surely already had a sufficient recompense, in having been permitted to draw out your head in safety from the mouth and jaws of a wolf."
In serving the wicked, expect no reward, and be thankful if you escape injury for your pains."
set {oldTids, pcount, i, my nl} to {AppleScript's text item delimiters, count paragraphs of my pp, 1, {}}
repeat pcount times
set {AppleScript's text item delimiters, thisL, AppleScript's text item delimiters} to {tab, text of (paragraph i of my pp), space}
set {end of my nl, i} to {"" & (i & space & (thisL as text)), i + 1}
end repeat
set AppleScript's text item delimiters to oldTids
nl
This is a more “message oriented approach”, I think it looks better, and thinks it should perform as fast as the former.
property pp : ""
property ml : {}
property nl : {}
property thisL : ""
set pp to "A WOLF who had a bone stuck in his throat hired a Crane, for a large sum, to put her head into his mouth and draw out the bone.
When the Crane had extracted the bone and demanded the promised payment, the Wolf, grinning and grinding his teeth, exclaimed:
"Why, you have surely already had a sufficient recompense, in having been permitted to draw out your head in safety from the mouth and jaws of a wolf."
In serving the wicked, expect no reward, and be thankful if you escape injury for your pains."
set {oldTids, my ml, pcount, i, thisLine, my nl} to {AppleScript's text item delimiters, paragraphs of my pp, count paragraphs of my pp, 1, "", {}}
repeat pcount times
tell (a reference to AppleScript's text item delimiters) to set contents to tab
tell (a reference to thisL) to set contents to text items of paragraph i of my pp
tell (a reference to AppleScript's text item delimiters) to set contents to space
tell (a reference to thisL) to set end of my nl to i & space & contents as text
set i to i + 1
end repeat
set AppleScript's text item delimiters to oldTids
nl