cat and grep without destroying file

Gerald Dachs ubuntu at dachsweb.de
Sun Sep 30 21:34:12 UTC 2007


Am Fri, 28 Sep 2007 14:22:13 +0100
schrieb "(``-_-ยดยด) -- Fernando" <ubuntu at bugabundo.net>:

> I've been trying to make a small shell script that would remove a
> line from a text file. But every time that I pipe the content of grep
> to the original file, the file ends up blank. So, I've made the
> script use a copy and them replace the original. It looks like this:
> #for i in $(/bin/ls -1); do cat $i | egrep -v ^Date > $i.new; mv
> $i.new $i; done
> 
> Isn't there any other way, without using the mv?

I don't think so, but there is no reason to use cat.
#for i in $(/bin/ls -1); do egrep -v ^Date < $i > $i.new; mv $i.new $i;
done

Gerald




More information about the ubuntu-users mailing list