Re: shell script replacing original file
- From: "Chris F.A. Johnson" <cfajohnson@xxxxxxxxx>
- Date: Fri, 28 Mar 2008 17:12:37 +0000
On 2008-03-28, Maxwell Lol wrote:
"Ming Ching TIew" <nospam@xxxxxxxxxx> writes:
I want to know if it is 100 % safe to do this :-
$ cat myfile | sed -e '...........' > myfile
(p.s. No need for cat.)
In this case, cat is needed so that myfile is opened before the
redirection truncates it. Even so, I wouldn't trust it.
Well, if you want to be 100% safe, perhaps something like this is better
sed -e '...........' <myfile > myfile.new
mv myfile myfile.old && mv myfile.new myfile && /bin/rm myfile.old
If it's a large file, and the disk fills up, it won't delete the
original file. (untested)
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
.
- Follow-Ups:
- Re: shell script replacing original file
- From: Janis
- Re: shell script replacing original file
- References:
- shell script replacing original file
- From: Ming Ching TIew
- Re: shell script replacing original file
- From: Maxwell Lol
- shell script replacing original file
- Prev by Date: Re: How to filter out without country's line ?
- Next by Date: Bash/Shell scripting practices/conventions
- Previous by thread: Re: shell script replacing original file
- Next by thread: Re: shell script replacing original file
- Index(es):
Relevant Pages
|
|