sed, awk, or something...help meeeeeeeeeee

Sharpe, Sam J sam.sharpe+lists.redhat at gmail.com
Mon Sep 28 20:12:41 UTC 2009


2009/9/28 Joerg Bergmann <email at jbergmann.de>:
> Am 28.09.2009 21:07, schrieb Sharpe, Sam J:
>> You specified that BB was to be /replaced/ with BBBB1, so you will
>> need to do this:
>>
>> [sam at samlap Desktop]$ sed -e '/BB/R file2' -e '/BB/d' file1

>
> This code may fail in case file 2 contains a line with BB only,
> in that case the replacement will be removed too.

Always best to check your statements before you criticise my code.

Because of the way sed works, the second -e operates on the original
line and not the replaced one, you are wrong and I am (still) correct.

[sam at samlap Desktop]$ cat file1
AA
BB
CC
DD

AA
BB
CC
DD
[sam at samlap Desktop]$ cat file2
BBBB1
BB
BBBB3

[sam at samlap Desktop]$ sed -e '/BB/R file2' -e '/BB/d' file1
AA
BBBB1
CC
DD

AA
BB
CC
DD

If you wanted to be totally correct, you should actually do:

$ sed -e '/^BB$/R file2' -e '/^BB$/d' file1

Laterz,

Sam




More information about the fedora-list mailing list