right justify each line?

"Daniel Goldman [email protected] [sed-users]" <[email protected]>
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
Hi,

Assume each line in input.x has the same length.

$ cat input.x
99
    99
  9
  9 9
99999

I want to right justify each line, so output.x would be:

$ cat output.x
    99
    99
     9
   9 9
99999

What is simplest way to convert input.x to output.x?

I tried the following, but does not work, because of greedy evaluation, 
\2 always encompasses the entire line.

$ sed "s/^\(.*\)\( *\)$/\2\1/" input.x

Thanks,
Daniel
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.