Hi
I have a HUGE data file multiple lines of data. I want to delete just
the first line from it. How to do it efficiently?
thanks
suresh
Hi
I have a HUGE data file multiple lines of data. I want to delete just
the first line from it. How to do it efficiently?
thanks
suresh
Would this work for you?
tail -n +2 original.file > modified.file
HTH,
Chris
On Jun 3, 1:59 pm, suresh <suresh.amritap...@gmail.com> wrote:
Hi
I have a HUGE data file multiple lines of data. I want to delete just
the first line from it. How to do it efficiently?thanks
suresh
Depends what you mean by "efficiently".
Removing data from the end of a file takes close to no time at all, if you do
it right -- it just requires truncating the file.
Removing data from the beginning of a file, or the middle of a file, isn't
something most filesystems will let you do. As Chris said, you're going to
have to read the entire file in (minus the line you want removed) and output
it to another file. (Or rather, that's what his tail command does.)
So, if we're talking about a multi-gigabyte file, it's going to take a few
minutes.
On Tuesday 03 June 2008 14:59:17 suresh wrote:
Hi
I have a HUGE data file multiple lines of data. I want to delete just
the first line from it. How to do it efficiently?
# I have a HUGE data file multiple lines of data. I want to delete just
# the first line from it. How to do it efficiently?
i think you want something fast yet clean ruby solution.
maybe something like,
botp@botp-desktop:~$ cat test.txt
this line will be deleted
2nd line
3rd asdfasdf line
4th qwerty line
5th
6th six
7th 777777777777
botp@botp-desktop:~$ irb
irb(main):001:0> File.open("newfile","w") do |fw|
irb(main):002:1* File.open("test.txt") do |fr|
irb(main):003:2* fr.gets
irb(main):004:2> fw.write fr.read
irb(main):005:2> end
irb(main):006:1> end
=> 72
botp@botp-desktop:~$ cat newfile
2nd line
3rd asdfasdf line
4th qwerty line
5th
6th six
7th 777777777777
just add some checks/rescues so that it will work on all your cases.
kind regards -botp
From: suresh [mailto:suresh.amritapuri@gmail.com]
suresh wrote:
HiI have a HUGE data file multiple lines of data. I want to delete just
the first line from it. How to do it efficiently?thanks
suresh
csplit file 1 '{1}'
sed -i "" '1d' file # in-place without backup
Cheers,
j.k.
--
Posted via http://www.ruby-forum.com/\.
Hi Chris
Thanks, I was not aware of the +2 option...
suresh
On Jun 4, 1:48 am, Chris Shea <cms...@gmail.com> wrote:
On Jun 3, 1:59 pm, suresh <suresh.amritap...@gmail.com> wrote:
> Hi
> I have a HUGE data file multiple lines of data. I want to delete just
> the first line from it. How to do it efficiently?> thanks
> sureshWould this work for you?
tail -n +2 original.file > modified.file
HTH,
Chris
Hi
BTW is there any equivalent method equivalent to linux tail in ruby?
suresh
On Jun 4, 1:48 am, Chris Shea <cms...@gmail.com> wrote:
On Jun 3, 1:59 pm, suresh <suresh.amritap...@gmail.com> wrote:
> Hi
> I have a HUGE data file multiple lines of data. I want to delete just
> the first line from it. How to do it efficiently?> thanks
> sureshWould this work for you?
tail -n +2 original.file > modified.file
HTH,
Chris
Chris Shea wrote:
On Jun 3, 1:59 pm, suresh <suresh.amritap...@gmail.com> wrote:
I have a HUGE data file multiple lines of data. I want to delete just
the first line from it. How to do it efficiently?tail -n +2 original.file > modified.file
For the sake of trivia, sed (stream editor) also does the job:
sed 1d original.file > modified.file # 1d means delete line 1
--
Posted via http://www.ruby-forum.com/\.
If that's all you want (and you're not frightened by the command-line options):
ruby -i -n -e 'puts $_ if $. > 1' lines.txt
Of if you want to keep the original in lines.txt.orig
ruby -i.orig -n -e 'puts $_ if $. > 1' lines.txt
-Rob
On Jun 4, 2008, at 9:16 PM, Peña, Botp wrote:
From: suresh [mailto:suresh.amritapuri@gmail.com]
# I have a HUGE data file multiple lines of data. I want to delete just
# the first line from it. How to do it efficiently?i think you want something fast yet clean ruby solution.
maybe something like,
botp@botp-desktop:~$ cat test.txt
this line will be deleted
2nd line
3rd asdfasdf line
4th qwerty line
5th
6th six
7th 777777777777botp@botp-desktop:~$ irb
irb(main):001:0> File.open("newfile","w") do |fw|
irb(main):002:1* File.open("test.txt") do |fr|
irb(main):003:2* fr.gets
irb(main):004:2> fw.write fr.read
irb(main):005:2> end
irb(main):006:1> end
=> 72botp@botp-desktop:~$ cat newfile
2nd line
3rd asdfasdf line
4th qwerty line
5th
6th six
7th 777777777777just add some checks/rescues so that it will work on all your cases.
kind regards -botp
Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
Jimmy Kofler wrote:
...
csplit file 1 '{1}'
...
csplit -k file 1 '{1}'
--
Posted via http://www.ruby-forum.com/\.
ruby -n -e 'print $_ if $.>1' original.file > modified.file
Regards,
Park Heesob
2008/6/4 suresh <suresh.amritapuri@gmail.com>:
On Jun 4, 1:48 am, Chris Shea <cms...@gmail.com> wrote:
On Jun 3, 1:59 pm, suresh <suresh.amritap...@gmail.com> wrote:
> Hi
> I have a HUGE data file multiple lines of data. I want to delete just
> the first line from it. How to do it efficiently?> thanks
> sureshWould this work for you?
tail -n +2 original.file > modified.file
HTH,
ChrisHi
BTW is there any equivalent method equivalent to linux tail in ruby?
Not really, but it shouldn't be difficult to build. Maybe trickier to build
efficiently, though.
On Wednesday 04 June 2008 04:59:12 suresh wrote:
BTW is there any equivalent method equivalent to linux tail in ruby?
Hi Park Heesob
Thanks. But how can this be done inside a .rb file? The above must be
from command line right?
suresh
On Jun 4, 3:19 pm, Heesob Park <pha...@gmail.com> wrote:
2008/6/4 suresh <suresh.amritap...@gmail.com>:
> On Jun 4, 1:48 am, Chris Shea <cms...@gmail.com> wrote:
>> On Jun 3, 1:59 pm, suresh <suresh.amritap...@gmail.com> wrote:>> > Hi
>> > I have a HUGE data file multiple lines of data. I want to delete just
>> > the first line from it. How to do it efficiently?>> > thanks
>> > suresh>> Would this work for you?
>> tail -n +2 original.file > modified.file
>> HTH,
>> Chris> Hi
> BTW is there any equivalent method equivalent to linux tail in ruby?
ruby -n -e 'print $_ if $.>1' original.file > modified.file
Regards,
Park Heesob
There's no core method, but there is a library:
http://raa.ruby-lang.org/project/file-tail/
Regards,
Dan
On Jun 4, 11:57 am, David Masover <ni...@slaphack.com> wrote:
On Wednesday 04 June 2008 04:59:12 suresh wrote:
> BTW is there any equivalent method equivalent to linux tail in ruby?
Not really, but it shouldn't be difficult to build. Maybe trickier to build
efficiently, though.
Hi,
2008/6/4 suresh <suresh.amritapuri@gmail.com>:
On Jun 4, 3:19 pm, Heesob Park <pha...@gmail.com> wrote:
2008/6/4 suresh <suresh.amritap...@gmail.com>:
> On Jun 4, 1:48 am, Chris Shea <cms...@gmail.com> wrote:
>> On Jun 3, 1:59 pm, suresh <suresh.amritap...@gmail.com> wrote:>> > Hi
>> > I have a HUGE data file multiple lines of data. I want to delete just
>> > the first line from it. How to do it efficiently?>> > thanks
>> > suresh>> Would this work for you?
>> tail -n +2 original.file > modified.file
>> HTH,
>> Chris> Hi
> BTW is there any equivalent method equivalent to linux tail in ruby?
ruby -n -e 'print $_ if $.>1' original.file > modified.file
Regards,
Park Heesob
Hi Park Heesob
Thanks. But how can this be done inside a .rb file? The above must be
from command line right?
It is equivalent to
while gets
print $_ if $.>1
end
Regards,
Park Heesob
Thanks Park Heesob, thank you
suresh
On Jun 4, 5:20 pm, Heesob Park <pha...@gmail.com> wrote:
Hi,
2008/6/4 suresh <suresh.amritap...@gmail.com>:
> On Jun 4, 3:19 pm, Heesob Park <pha...@gmail.com> wrote:
>> 2008/6/4 suresh <suresh.amritap...@gmail.com>:>> > On Jun 4, 1:48 am, Chris Shea <cms...@gmail.com> wrote:
>> >> On Jun 3, 1:59 pm, suresh <suresh.amritap...@gmail.com> wrote:>> >> > Hi
>> >> > I have a HUGE data file multiple lines of data. I want to delete just
>> >> > the first line from it. How to do it efficiently?>> >> > thanks
>> >> > suresh>> >> Would this work for you?
>> >> tail -n +2 original.file > modified.file
>> >> HTH,
>> >> Chris>> > Hi
>> > BTW is there any equivalent method equivalent to linux tail in ruby?
>> ruby -n -e 'print $_ if $.>1' original.file > modified.file
>> Regards,
>> Park Heesob
> Hi Park Heesob
> Thanks. But how can this be done inside a .rb file? The above must be
> from command line right?It is equivalent to
while gets
print $_ if $.>1
endRegards,
Park Heesob