Deleting first line from a file

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

On Jun 3, 1:59 pm, suresh [email protected] 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

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.

On Jun 4, 1:48 am, Chris S. [email protected] wrote:

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

On Jun 4, 1:48 am, Chris S. [email protected] wrote:

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

2008/6/4 suresh [email protected]:

ruby -n -e ‘print $_ if $.>1’ original.file > modified.file

Regards,

Park H.

Hi,

2008/6/4 suresh [email protected]:

I have a HUGE data file multiple lines of data. I want to delete just
Chris

Hi Park H.

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

On Jun 4, 5:20 pm, Heesob P. [email protected] wrote:

Hi

print $_ if $.>1
end

Regards,

Park H.

Thanks Park H., thank you
suresh

On Jun 4, 3:19 pm, Heesob P. [email protected] wrote:

the first line from it. How to do it efficiently?

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

Hi Park H.

Thanks. But how can this be done inside a .rb file? The above must be
from command line right?

suresh

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.

Chris S. wrote:

On Jun 3, 1:59 pm, suresh [email protected] 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

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:

this line will be deleted
irb(main):003:2* fr.gets
6th six
7th 777777777777

just add some checks/rescues so that it will work on all your cases.

kind regards -botp

Rob B. http://agileconsultingllc.com
[email protected]

From: suresh [mailto:[email protected]]

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

On Jun 4, 11:57 am, David M. [email protected] 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.

There’s no core method, but there is a library:

http://raa.ruby-lang.org/project/file-tail/

Regards,

Dan

Jimmy K. wrote:

csplit file 1 ‘{1}’

csplit -k file 1 ‘{1}’

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?

thanks
suresh

csplit file 1 ‘{1}’

sed -i “” ‘1d’ file # in-place without backup

Cheers,

j.k.