| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
That's very clever. Here is my best understanding how Rakesh's solution
works, please correct me if I didn't get it right.
$ N=4
$ echo abcd | sed -n ":k G; P; s/\n/&/$N; Tk"
abcd
abcd
abcd
abcd
- Each time through loop, P prints abcd (line #1 of PatSpace).
- For counter, G appends \n to PatSpace each time through loop.
- Seems like the order of G and P does not matter.
- Normally, s does not substitute, so T loops.
- When P has run 4 times, PatSpace has \n\n\n\n, s substitutes \n #4, T
does not loop, sed exits.
-------------------
I made a simpler version of Davide's solution, I think it still works,
he already explained how the solution works.
$ N=4
$ echo abcd | sed -e ":k x; /z\{$N\}/ d" -e 's/$/z/; x; p; bk'
abcd
abcd
abcd
abcd
---------------------
Daniel
>
>
> We can simplify the sed code a bit , since the pattern space
> gets loaded by input.
> Note: The $N even though it looks like a valid sed syntax, but
> here it is a shell variable N, storing the number of times
> to print the string "abcd". N > 0
>
>
> sed -ne "
>
> :loop
> G;P
> s/\n/&/$N
> Tloop
> "
>
>
>
>
>
> [Non-text portions of this message have been removed]
>
>
>
> ------------------------------------
> Posted by: [email protected]
> ------------------------------------
>