Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > deleting first line from a file

Reply
Thread Tools

deleting first line from a file

 
 
suresh
Guest
Posts: n/a
 
      06-03-2008
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
 
Reply With Quote
 
 
 
 
Chris Shea
Guest
Posts: n/a
 
      06-03-2008
On Jun 3, 1:59 pm, suresh <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
David Masover
Guest
Posts: n/a
 
      06-03-2008
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.

 
Reply With Quote
 
suresh
Guest
Posts: n/a
 
      06-04-2008
On Jun 4, 1:48 am, Chris Shea <(E-Mail Removed)> wrote:
> On Jun 3, 1:59 pm, suresh <(E-Mail Removed)> 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
 
Reply With Quote
 
suresh
Guest
Posts: n/a
 
      06-04-2008
On Jun 4, 1:48 am, Chris Shea <(E-Mail Removed)> wrote:
> On Jun 3, 1:59 pm, suresh <(E-Mail Removed)> 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
 
Reply With Quote
 
Heesob Park
Guest
Posts: n/a
 
      06-04-2008
2008/6/4 suresh <(E-Mail Removed)>:
> On Jun 4, 1:48 am, Chris Shea <(E-Mail Removed)> wrote:
>> On Jun 3, 1:59 pm, suresh <(E-Mail Removed)> 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

 
Reply With Quote
 
suresh
Guest
Posts: n/a
 
      06-04-2008
On Jun 4, 3:19 pm, Heesob Park <(E-Mail Removed)> wrote:
> 2008/6/4 suresh <(E-Mail Removed)>:
>
>
>
> > On Jun 4, 1:48 am, Chris Shea <(E-Mail Removed)> wrote:
> >> On Jun 3, 1:59 pm, suresh <(E-Mail Removed)> 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
 
Reply With Quote
 
Heesob Park
Guest
Posts: n/a
 
      06-04-2008
Hi,

2008/6/4 suresh <(E-Mail Removed)>:
> On Jun 4, 3:19 pm, Heesob Park <(E-Mail Removed)> wrote:
>> 2008/6/4 suresh <(E-Mail Removed)>:
>>
>>
>>
>> > On Jun 4, 1:48 am, Chris Shea <(E-Mail Removed)> wrote:
>> >> On Jun 3, 1:59 pm, suresh <(E-Mail Removed)> 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

 
Reply With Quote
 
suresh
Guest
Posts: n/a
 
      06-04-2008
On Jun 4, 5:20 pm, Heesob Park <(E-Mail Removed)> wrote:
> Hi,
>
> 2008/6/4 suresh <(E-Mail Removed)>:
>
> > On Jun 4, 3:19 pm, Heesob Park <(E-Mail Removed)> wrote:
> >> 2008/6/4 suresh <(E-Mail Removed)>:

>
> >> > On Jun 4, 1:48 am, Chris Shea <(E-Mail Removed)> wrote:
> >> >> On Jun 3, 1:59 pm, suresh <(E-Mail Removed)> 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
 
Reply With Quote
 
David Masover
Guest
Posts: n/a
 
      06-04-2008
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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting data from the file without deleting the file first crea C++ 2 12-28-2012 11:50 PM
Read a file line by line and write each line to a file based on the5th byte scad C++ 23 05-17-2009 06:11 PM
Open file, get first line, delete first line close file Richard Schneeman Ruby 16 08-26-2008 11:54 PM
Deleting a File from Hardrive and Deleting a SubKey in Registry Harry Barker C++ 2 04-19-2006 09:34 AM
Read a file line by line with a maximum number of characters per line Hugo Java 10 10-18-2004 11:42 AM



Advertisments