sed woes

twitchej at xmission.com twitchej at xmission.com
Thu Dec 14 13:37:02 MST 2006


Quoting Michael L Torrie <torriem at chem.byu.edu>:

> On Thu, 2006-12-14 at 12:28 -0700, Daniel wrote:
>> I understand that uniq would work in this particular instance.  The
>> bigger question is why does
>> sed -e 's/ALL:211\.94\.73\.199//2' /etc/hosts.deny
>> not work the way the documentation says it will?

So I guess the 2 would replace the second occurance on the same line.

echo "1dot:2dot:1dot:3dot" | sed 's/1dot/4dot/2'
1dot:2dot:4dot:3dot

> Well, in line mode, sed works on one line at a time, on all the
> characters in the stream from the beginning of the line to the end of
> the line.  The line break character isn't a part of things by default I
> think.  Thus you are replacing all the characters in the line with "",
> giving you a blank line.  Makes sense to me.
>
> Michael
>
>
>>
>> -Daniel
>>
>> On 12/14/06, Paul Seamons <paul at seamons.com> wrote:
>> > The other replies will work well - but what if you want it to stay 
>> in order?
>> >
>> > Then here is a short perl line.
>> >
>> > [paul at www1 lib]$ echo "foo
>> > foo
>> > bar
>> > foo
>> > bar
>> > bing" | perl -ne 'print if ! $used{$_}++'
>> > foo
>> > bar
>> > bing
>> >
>> > And if you only want to deal with lines with ips - then you could do
>> >
>> > cat /etc/hosts.deny | perl -ne 'print if ! /^ALL:(\S+)/ || ! $used{$1}++'
>> >
>> > Paul
>> >
>> > /*
>> > PLUG: http://plug.org, #utah on irc.freenode.net
>> > Unsubscribe: http://plug.org/mailman/options/plug
>> > Don't fear the penguin.
>> > */
>> >
>>
>> /*
>> PLUG: http://plug.org, #utah on irc.freenode.net
>> Unsubscribe: http://plug.org/mailman/options/plug
>> Don't fear the penguin.
>> */
>>
>
>
> /*
> PLUG: http://plug.org, #utah on irc.freenode.net
> Unsubscribe: http://plug.org/mailman/options/plug
> Don't fear the penguin.
> */
>





More information about the PLUG mailing list