|
From: | clark wang |
Subject: | Re: [Help-bash] Quick prepend to file using echo |
Date: | Sat, 19 May 2012 20:05:14 +0800 |
On Wednesday, May 16, 2012 07:16:03 PM Chris Jones wrote:> ---- $ echo "// vim: set tw=80 syntax=sh:" >> ~/.bashrc
> Using ‘echo’, it's easy to append to a file:
>
> ----------------------------------------------------------------------------
> ----------------------------------------------------------------------------People are quick to jump to tmp files and GNU sed -i.
> ----
>
> But how do you do it the other way around..? Prepend to a file
> so-to-speak..?
>
> I saw a couple of threads in stackoverflow.com with complicated one-liners
> and everybody appeared to conclude that you need a temp file anyway..
This shouldn't be
recommended before first ruling out ed (or ex). Short of moving to a different
scripting language, a real editor is still the only sane way to modify a file
"in-place" from a shell script. sed -i is a hack. Some use it if some sed
feature specifically makes the job easier, though I suspect the real reason is
almost always because they don't want to have to learn something else.
GNU's
ed is really not that bad to work with.
--
Dan Douglas
[Prev in Thread] | Current Thread | [Next in Thread] |