From: Robert Klemme Date: 2007-06-14T06:30:28+09:00 Subject: Re: why writing the file is partial On 13.06.2007 20:16, Rick DeNatale wrote: > On 6/13/07, Li Chen wrote: >> > >> > But this will only work in the case where the replacement is the same >> > length at the original, if you you're either going to leave stuff >> > behind, or will overwrite the next line. In either case you're more >> > likely to end up with gibberish than something you like. >> >> What am I supposed to do if the replacement is not same size? > > Write to another file, then rename when you are done. > > This is standard posix practice. And you can even do it in a one liner. See ruby's command line options -i and -p. You can then do ruby -i.bak -pe 'gsub /.../, "..."' file Kind regards robert