On Tue, Feb 26, 2008 at 9:09 PM, David Korn <[EMAIL PROTECTED]> wrote:
>  Yes, this already exists,  you can do
>
>  $ nl myfile | iconv -fL1 -tUTF-8 1<> myfile
>
>  <> opens the file for reading and writing.  The default is file descriptor 
> is 0.
>
>         tr [A-Z] [a-z] < file 1<> file

:-)  Thanks. "In-place" was probably the wrong word I used, since
it should reliably work for expanding also, as Icarus points out.

The operator might act somewhat like &&> (although this already
has another meaning). On the left of it, there is an implicit set -o
pipefail, and on the right, the file is only created on success, and
is guaranteed to have a different inum. That means a temporary file
must be created first, and then on success, the old one gets unliked
(possibly implicitly by rename).

While my initial idea was to type less, I think similar mechanisms
are also used to replace files that are potentially actively used: pages
on a web server, binaries and shared libraries (although they probably
do an additional backup step first -- but still, the file is replaced in
one operation instantly). So the whole thing is like a transaction,
and if the pipe failed, nothing happened (the old file is still there),
it's "rolled back". And I could also easily check that by comparing
the inum (say, if another process doesn't know the exit status).
And I wouldn't have to worry about file locking, etc. -- that would
be done without my knowing, if necessary.

Well, just an idea... I don't want to turn it into a database. :-)


Thanks,
    Markus
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to