cat and grep without destroying file
Mr Shunz
mrshunz at gmail.com
Wed Oct 3 16:02:26 UTC 2007
On 10/2/07, (``-_-´´) -- Fernando <ubuntu at bugabundo.net> wrote:
> On Sunday 30 September 2007 15:27:15 Chris Malton wrote:
> > (``-_-´´) -- Fernando wrote:
> > > 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, some how. I have never successfully done it without
> > an mv or a cp.
> >
> > Chris
>
> Thanks, Chris.
>
Hi,
As someone stated before, you can use sed "inline" function, as:
for i in $(/bin/ls -1); do
sed '/^Date/d' -i $i
done
--
Daniele Santi .o.
MrShunz at gmail.com ..o |,,,/_
Linux User #415108 ooo
---------------------------------------------------------
() ascii ribbon campaign - against html mail
/\ - against microsoft attachments
---------------------------------------------------------
More information about the ubuntu-users
mailing list