7stud2
(7stud --)
4 September 2012 13:33
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
···
--
Posted via http://www.ruby-forum.com/ .
7stud2
(7stud --)
4 September 2012 16:15
2
Read the file into a string, modify the string, overwrite the file with
the new string.
···
--
Posted via http://www.ruby-forum.com/ .
7stud2
(7stud --)
4 September 2012 16:23
3
Joel Pearson 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?
···
--
Posted via http://www.ruby-forum.com/\ .
Then read line by line writing to a temporary file, skipping the line
you want to delete, then rename the file.
Jesus.
···
On Tue, Sep 4, 2012 at 6:23 PM, Ferdous ara <lists@ruby-forum.com> wrote:
Joel Pearson 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?
stomar
(stomar)
4 September 2012 16:39
5
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?
···
Am 04.09.2012 18:23, schrieb Ferdous ara:
Joel Pearson 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?
--
<https://github.com/stomar/> ;
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