Re: right justify each line?

"Thierry Blanc [email protected] [sed-users]" <[email protected]>
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
 think this line should enter the sed "hall of fame" (i.e. sed1line.txt)

On 16/11/15 16:55, 'Ruud H.G. van Tol' [email protected] [sed-users] wrote:
> On 2015-11-16 05:27, Daniel Goldman [email protected] [sed-users] wrote:
>> On 11/15/2015 6:33 AM, 'Ruud H.G. van Tol' [sed-users] wrote:
>>> As was suggested before, if all lines have the right number of trailing
>>> spaces, then just move those to the front.
>>>
>>> sed 's~^\(.*[^ ]\)\(  *\)~\2\1~' input.txt
>> Ruud, you're right, you figured out the shortest solution, and it does
>> not require knowledge of the line length. Again using dashes instead of
>> blanks, my original simple-minded attempt does NOT work, \1 is greedy
>> and eats up the entire line, so \2 is always empty.
>> [...]
>> $ sed -r 's/^(.*[^-])(-*)$/\2\1/' input.txt
>> ----9
>> ----9
>> ----9
>> --9-9
>> --9-9
>> --9-9
>> -----
>> 99999
>>
>> I did slightly modify your solution, adding needed anchor '$' to correct
>> a glitch processing line 5 in the test case above.
> 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,}
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.