| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
Thank you for trying. But I don't think that right justifies. Actually,
I don't think it does any net effect...
Correct me if I'm wrong, but AFAICT: 1) s #1 adds 5 spaces to beginning
of each line. 2) s #2 only retains last 5 chars in the line (omits 5
leading spaces), leaving us back where we started. :(
Even if it did work, it can't have a hard coded character count like
five dots in (.....$) because as I mentioned, in this case, each line
has five chars, but it could be a different number of chars.
Given how yahoo mangles the posts (it messed up Thierry's post on yahoo
website, squeezing the blanks down to one blank), I would like to recast
the input and output files to the form with the dashes.
$ cat input.x
99---
---99
-9---
-9-9-
99999
$ cat output.x
---99
---99
----9
--9-9
99999
I believe it's exactly the same scenario, just pad on the left with
dashes instead of blanks, and we can avoid confusion from yahoo playing
around with blanks. If the solution works for the case with the dashes,
it will work for the case with spaces.
sed -r "s/^(.*)(-*)$/\2\1/" would be my initial failed try
sed -r 's|^|-----|;s|.*(.....$)|\1|' would be Thierry's try
Thanks,
Daniel
On 11/14/2015 10:33 AM, Thierry Blanc [sed-users] wrote:
>
>
> sed -r 's|^| |;s|.*(.....$)|\1|'
>
> add spaces to the beginning of line, as many as the maximum line width
> cut from the end of the line the amount of chars of the line width
>
>
>
> On 14/11/15 19:19, Daniel Goldman [email protected] [sed-users] wrote:
>> I double-checked my sent folder, and a copy sent to myself. Actually, I
>> did post sensibly, but yahoo did not transmit sensibly. Unfortunately,
>> yahoo stripped out leading blanks from the lines, so yes it ended up
>> input.x = output.x :( So so thanks for asking.
>>
>> Please look at the following, and imagine that the colons are not there,
>> and that's how I posted. In this case, each line has five characters,
>> but it could be a different number of characters.
>>
>> $ cat input.x
>> :99 :
>> : 99:
>> : 9 :
>> : 9 9 :
>> :99999:
>>
>> $ cat output.x
>> : 99:
>> : 99:
>> : 9:
>> : 9 9:
>> :99999:
>>
>> In case yahoo mangles the above, here is another way to display it,
>> where you would please imagine that each '-' is a blank.
>>
>> $ cat input.x
>> 99---
>> ---99
>> -9---
>> -9-9-
>> 99999
>>
>> $ cat output.x
>> ---99
>> ---99
>> ----9
>> --9-9
>> 99999
>>
>> Thanks,
>> Daniel
>>
>> On 11/14/2015 9:36 AM, Rakesh Sharma wrote:
>>> Your input.x = output.x and also what do you mean each line in input.x has the same length? look at the line 99999.
>>>
>>> You need to post sensibly first.
>>>
>>>
>>> ________________________________
>>> From: [email protected] <[email protected]> on behalf of Daniel Goldman [email protected] [sed-users] <[email protected]>
>>> Sent: Saturday, November 14, 2015 9:25 AM
>>> To: [email protected]
>>> Subject: right justify each line?
>>>
>>>
>>>
>>> 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
>>>
>>>
>>>
>>>
>>> [Non-text portions of this message have been removed]
>>>
>>>
>>
>
>
>
> ------------------------------------
>
> ------------------------------------
>
------------------------------------
------------------------------------
--
------------------------------------
Yahoo Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/sed-users/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/sed-users/join
(Yahoo! ID required)
<*> To change settings via email:
[email protected]
[email protected]
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo Groups is subject to:
https://info.yahoo.com/legal/us/yahoo/utos/terms/