| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
Ruud, you did the hard part. The correction was easier.
No, I didn't miss that it had two spaces. I intentionally changed it
from two to one, to make the expression shorter, and it still produces
the same right-justified output file.
However, you are right that "busywork" would result, because with (-*)
(one space) the s command always runs (swaps) on a non-empty line,
whereas with (--*) (two spaces) s only runs when trailing blanks. So I
agree two spaces is better, because no point in swapping when \2 is
empty, it makes the intention clearer, and is plenty short enough.
sed -r 's/^(.*[^-])(-*)$/\2\1/' input.txt # one space (dashes)
sed -r 's/^(.*[^-])(--*)$/\2\1/' input.txt # two spaces
Thanks,
Daniel
On 11/16/2015 7:55 AM, 'Ruud H.G. van Tol' [sed-users] wrote:
>
>
> Good correction, thanks.
>
> You appear to have missed that it had ' *',
> which has 2 spaces, to keep it from doing busywork.
>
> Some other ways to express the same:
> [ ][ ]*
> [ ]{1,}
>