in reply to Re^2: One-liner to append text at fixed column
in thread One-liner to append text at fixed column
Ok, I think I did not understand the original problem. I thought you were trying to 'align' all the comments from a text like this:
perl -E"say '.' x rand(80) . '# test comment' for 1..3" ......................# test comment .................................# test comment ...................................................................... +....# test comment
So eventually I came up with this which I think is too complex.
perl -E"say '.' x rand(80) . '# test comment' for 1..10" |perl -lpe " +/\s*#(.*)$|$/ && ( substr( $_, $-[0], length($_) ) = qq{ }x(68 - $-[ +0] + 2) . qq{ #$1} ) ............................................... + # test comment .......................................................... + # test comment ....................................... + # test comment ............................................................ + # test comment ...................................................................... +.... # test comment ...... + # test comment ........................................ + # test comment ............................... + # test comment ................................................... + # test comment ................................... + # test comment
Maybe it can be rewritten with a printf but I will leave it with this.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: One-liner to append text at fixed column
by LanX (Saint) on Nov 16, 2018 at 15:55 UTC |