Date: Thu, 10 Jul 1997 03:17:49 +0200 From: Kent Boortz <kent@erlang.ericsson.se> To: simat@enta.net Cc: kent@erlang.ericsson.se Subject: Re: SED remove from live file Message-ID: <199707100117.DAA03053@townsend.ericsson.se> In-Reply-To: Your message of "Wed, 09 Jul 1997 21:42:33 %2B0000" References: <33C3F7B9.5636@enta.net>
next in thread | previous in thread | raw e-mail | index | archive | help
> i.e sed "s/\.//g" simat.dat strip all . 's from simat.dat > > if we use > > cat simat.dat | sed "s/\.//g" > simat.dat > then we end up with simat.dat being empty and 0 bytes. > > There must be a nice way to do this without having to > create a pooy tmp file. Nop, there isn't. All file systems I know of use sequential files divided in blocks. You can modify bytes inside the file but not add or remove anything except from the end of the file. But some commands try to hide the fact. In Perl some extra options to handle this % perl -p -i.bak -e "s/\.//g;" simat.dat This will store the old file with a ".bak" extension and create a new file with the name it had before the copy. But then you are left with a ".bak file" so maybe you could define a small script #!/bin/sh # Usage: replace Pattern Files...... # NOTE: Some "sed" implementations will truncate long lines pattern=$1 shift names=$@ for name in $names; do new=/tmp/$name.new old=/tmp/$name.old cat "$name" | sed "$pattern" > "$new" mv "$name" "$old" mv "$new" "$name" rm -f $old done The script is not tested..... /kgb
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199707100117.DAA03053>
