| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
I agree, it should enter the "hall of fame".
Right justifying is a real-world task. IMO, sed is very practical and
useful, and I think this is a good example.
For me, it solved my little problem. I appreciate the help from Rakesh,
Thierry, and Ruud.
Daniel
On 11/16/2015 9:52 AM, Thierry Blanc [sed-users] wrote:
> 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' wrote:
>> On 2015-11-16 05:27, Daniel Goldman 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,}
>>
>
>