[TAG] 2c tip: filtering in-place
ben at callahans.org
Fri Mar 19 18:39:34 MSK 2004
On Fri, Mar 19, 2004 at 02:33:21PM +0530, Kapil Hari Paranjape wrote:
> I have always thought that filtering files "in-place" was
> not possible from the command line...
> ...until today---one lives and learns.
> dd if=file bs=4k | filter | dd of=file bs=4k conv=notrunc
> Where "file" is the file you want to filter and "filter"
> is the filtering program you want to apply.
The "buffer" program does exactly the same as the above; the process is
buffer < foo | filter > foo
If the file is bigger than 1MB, you'll need to specify a larger queue
with the "-m" option, but that's usually not an issue.
Conversely, as Thomas mentioned, you could use Perl's, etc. "in-place
perl -i -wpe'y/a-zA-Z/n-za-mN-ZA-M/' file
# lc everything
perl -i -wpe'$_=lc' file
* Ben Okopnik * okopnik.freeshell.org * Technical Editor, Linux Gazette *
-=-=-=-=-=o0o=-=-=-=-= <http://linuxgazette.net/> =-=-=-=-=o0o=-=-=-=-=-
More information about the TAG