[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: New feature suggestion: "r" command to accept address zero

From: Jim Meyering
Subject: Re: New feature suggestion: "r" command to accept address zero
Date: Fri, 13 Aug 2021 12:39:10 +0200

On Wed, Aug 11, 2021 at 9:27 PM Assaf Gordon <> wrote:
> I'd like to suggest a small feature:
> ====
> The 'r' command can be used with address zero, effectively prepending
> a file to the beginning of the input file, e.g.:
>      sed '0rA.TXT' B.TXT > C.TXT
> is equivalent to:
>      cat A.TXT B.TXT > C.TXT
> With "sed -i", this allows safe in-place prepending of files.
> A typical example would be adding a license header to multiple source
> files:
>      sed -i '0rLICENSE' *.c *.h
>      find -iname '*.cpp' | xargs sed -i '0rLICENSE'
> Current cumbersome alternatives are:
>      sed -i -e 'x;${p;x};1rA.TXT' -e '1d'  B.TXT
>      sed -i '1ihello\nworld' B.TXT
>      # Or converting a file to an embedded string
>      # with "\n" then using "1i" :
>      sed -i -e '1i\' -e "$(sed -z 's/\n/\\n/g' A.TXT)" B.txt
> =====
> With "-i" this addresses several of the difficulties in Pádraig's
> document:
> And also does not require shell scripting, something like:
>      cat A.TXT B.TXT > C.TXT && MV C.TXT B.TXT
> I seem to remember talks about adding a generic coreutils program
> 'inplace', but until then, this could be a helpful alternative.

Hi Assaf,
I like the idea.
And the code. Nice work.
That all looks fine (of course modulo missing documentation).

Thank you!

reply via email to

[Prev in Thread] Current Thread [Next in Thread]