[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

deleting first line from a file

suresh

6/3/2008 7:59:00 PM

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
15 Answers

Chris Shea

6/3/2008 8:49:00 PM

0

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

David Masover

6/3/2008 9:02:00 PM

0

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?

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.

suresh

6/4/2008 9:46:00 AM

0

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 Chris

Thanks, I was not aware of the +2 option...

suresh

suresh

6/4/2008 9:59:00 AM

0

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?

suresh

Heesob Park

6/4/2008 10:19:00 AM

0

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
>> > 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

suresh

6/4/2008 11:28:00 AM

0

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?

suresh

Heesob Park

6/4/2008 12:20:00 PM

0

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

suresh

6/4/2008 12:49:00 PM

0

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
> end
>
> Regards,
>
> Park Heesob

Thanks Park Heesob, thank you
suresh

David Masover

6/4/2008 5:57:00 PM

0

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.


Suraj Kurapati

6/4/2008 7:22:00 PM

0

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-....