From cab760a1b7912548daf2fa033f11b4ea939a86f3 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 14 Jan 2015 15:08:36 -0500 Subject: this was sitting there --- .../wordpress/2011/05/why-sed-i-exists/index.html | 195 +++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 web/lukeshu.ath.cx/1/wordpress/2011/05/why-sed-i-exists/index.html (limited to 'web/lukeshu.ath.cx/1/wordpress/2011/05/why-sed-i-exists/index.html') diff --git a/web/lukeshu.ath.cx/1/wordpress/2011/05/why-sed-i-exists/index.html b/web/lukeshu.ath.cx/1/wordpress/2011/05/why-sed-i-exists/index.html new file mode 100644 index 0000000..d1955af --- /dev/null +++ b/web/lukeshu.ath.cx/1/wordpress/2011/05/why-sed-i-exists/index.html @@ -0,0 +1,195 @@ + + + + + Why `sed -i’ exists | ltsBlog + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + +

ltsBlog

+ + + + + + + + + + +
+ + + +
+

Why `sed -i’ exists

+ +
+

I’ve decided to to a morning-pages type thing here, just to get info out. This means that I’ll be posting 250-ish word weblog post
+snippits sharing whatever, and fairly frequently posting, if this works.

+

So, what is the purpose of the -i flag to sed? Simply, it edits the file in place, instead of dumping the edit to stdout.

+

Those of you familiar with “cat -v Considered Harmful” or just traditional UNIX design will say “bah, what a useless flag, just use sed 's/regex//' < file > file to write the changes back to the file.

+

But there’s a problem with this. There is a race condition, the file has been opened twice, once for reading, and once for writing. If they get closed in the wrong order, you will end up with an empty file. In my experience this very seldom happens. However, when you have a shell script that usually works, but just occaisionally corrupts your `database’, you’ll see why sed -i‘s important.

+ +
+
+ +
+ +
+ This entry was posted in Computers, morning-pages. Bookmark the permalink. + +
+
+ + + + + +
+
+

Leave a Reply

+
+

Your email address will not be published. Required fields are marked *

*

+ +

+

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

+ + + +

+
+
+ +
+ +
+ + + + + + -- cgit v1.2.3