aris
September 4, 2012, 3:33pm
1
Hi
i have a file this
/dev/cciss/c0d10p1 /root/file/file-55 ext3
defaults,noatime,nodiratime 1 0
/dev/cciss/c0d11p1 /root/file/file-11 ext3
defaults,noatime,nodiratime 1 0
#/dev/cciss/c0d12p1 /root/file/file-SPARE ext3
defaults,noatime,nodiratime 1 0
Now i want to delete
#/dev/cciss/c0d12p1 /root/file/file-SPARE ext3
defaults,noatime,nodiratime 1 0
which has SPARE word
so i am doing this .
require ‘fileutils’
f=File.new("fstab ")
f.each do |line|
instattr <<line
if line =~/SPARE/
DLETE THE LINE
end
end
end
But how to delete that line ???
Can any one please help me with this
Thanks
ferdous
September 4, 2012, 6:15pm
2
Read the file into a string, modify the string, overwrite the file with
the new string.
ferdous
September 4, 2012, 6:21pm
3
Joel P. wrote in post #1074655:
Read the file into a string, modify the string, overwrite the file with
the new string.
For a small file its fine. But if the file is big then
That’s the solution?
ferdous
September 4, 2012, 6:30pm
4
On Tue, Sep 4, 2012 at 6:23 PM, Ferdous ara [email protected]
wrote:
Joel P. wrote in post #1074655:
Read the file into a string, modify the string, overwrite the file with
the new string.
For a small file its fine. But if the file is big then
That’s the solution?
Then read line by line writing to a temporary file, skipping the line
you want to delete, then rename the file.
Jesus.
ferdous
September 4, 2012, 6:39pm
5
Am 04.09.2012 18:23, schrieb Ferdous ara:
Joel P. wrote in post #1074655:
Read the file into a string, modify the string, overwrite the file with
the new string.
For a small file its fine. But if the file is big then
That’s the solution?
You could read and write line by line (writing to a new file),
omitting the line you want to delete, then overwrite
the old file with the new file.
But IMO Joel’s suggestion is simpler. Is the file usually that big?
ferdous
September 4, 2012, 6:53pm
6
But IMO Joel’s suggestion is simpler. Is the file usually that big?
I have some massive files (1-3 MB in size) that I have to manipulate and
Ruby
handles them without any problems and very quickly (much faster than a
few other
languages I’ve tried this with).
Wayne