Subject: bug#36489: possible bug by sed?

From: Assaf Gordon <[email-masked]>
Date: Thu, 4 Jul 2019 02:20:33 -0600

tag 36489 moreinfo
stop

Hello,

On Wed, Jul 03, 2019 at 10:35:33AM -0400, Steven Abner wrote:
> Hi,
> Using:
> grep -rlI ~/Development/PheonixOS -e 'as_sys_types.h' | xargs sed -i
> [email-masked]@as_types.h@g'
> on ElementaryOS did its job except it truncated a few files' last line. In
> otherwords, file ends up one line
> short, and had no replacement on that line.
>  Only found problem because of had identical copies on my mac, and did same
> thing, except BSD variant:
> grep -rlI ~/Development/Pheonix -e 'as_sys_types.h' | xargs sed -i ""
> [email-masked]@as_types.h@g'
> Then I verify changes by using diff command. Several files on linux lost
> last line.
> As stated in subject, 'possible', because it could belong to 'xargs'?

We'll need a bit more information to be able to diagnose this issue.

First,
which version of 'sed' are you using (try "sed --version").
If this isn't a recent version (4.7), can you also try
with version 4.7 ?

Second,
Is this reproducible?
Can you narrow it down to a single file using only "sed" (without
grep/xargs) ?
If so, can you share the file?
(To ease testing, you can add a backup extension to the "-i" parameter,
similar to bsd: "sed -i.bak [...]" - the original files will be saved).

Third,
A cursory attempt to run a similar command on my computer
did not show this issue, I tried with the following commands:

    for i in a b c d e ; \
        do ( seq 10 ; printf "AAA as_sys_types.h\n" ) > $i ; done

    grep -rlI ./ -e 'as_sys_types.h' \
        | xargs sed -i [email-masked]@as_types.h@g'

regards,
 - assaf