Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to get the last 100 lines from a file and put into another file

7,228 views
Skip to first unread message

Edel

unread,
Aug 27, 2002, 5:24:01 AM8/27/02
to
I have a unix file 7.5M in size. I want to take the first 10 lines and
the last 100 lines and put these into another file without losing any
spaces.
I can't view the file using vi as the file is too big and when I use
the tail command, it will not get the last 100 lines - it only
retrieves the last 25 lines approx.
Can't use the grep command either as I will then lose the spaces.

Any ideas?

Christian

unread,
Aug 27, 2002, 5:58:47 AM8/27/02
to
"Edel" <ekea...@ddsi.ie> wrote in message
news:397e7fa6.0208...@posting.google.com...

tail -n filename will get the last n lines of file 'filename'


Andreas Fenner

unread,
Aug 27, 2002, 6:00:08 AM8/27/02
to
Edel wrote:
>
> I have a unix file 7.5M in size. I want to take the first 10 lines and

head -10 filename > tmpfile1

> the last 100 lines and put these into another file without losing any

tail -100 filename > tmpfile2

> spaces.

cat tmpfile1 tmpfile2 > resultfile

> I can't view the file using vi as the file is too big and when I use
> the tail command, it will not get the last 100 lines - it only
> retrieves the last 25 lines approx.
> Can't use the grep command either as I will then lose the spaces.
>
> Any ideas?

RTFM

man head
man tail

--
Dipl. Ing. Andreas Fenner, mailto:Andreas...@alcatel.de
Alcatel SEL AG, TS/EE, Holderäckerstr.10, 70499 Stuttgart, 0711/821-49823
-------------------------------------------------------------------------
Linux is like a Wigwam: no Windows, no Gates, Apache inside

Alexander von Alkier

unread,
Aug 27, 2002, 5:58:10 AM8/27/02
to

"Edel" <ekea...@ddsi.ie> schrieb im Newsbeitrag
news:397e7fa6.0208...@posting.google.com...

use "tail -100" to get the last 100 lines and pipe it to the file you want

alexander


Tony Walton - Sun Enterprise Services UK

unread,
Aug 27, 2002, 6:59:17 AM8/27/02
to
Edel wrote:
>
> I have a unix file 7.5M in size. I want to take the first 10 lines and
> the last 100 lines and put these into another file without losing any
> spaces.
>

$ cat <(head -10 myfile) <(tail -100 myfile) > anotherfile

In Korn shell.


--
Tony Walton

Anthony Mandic

unread,
Aug 27, 2002, 7:40:54 AM8/27/02
to
Tony Walton - Sun Enterprise Services UK wrote:

> $ cat <(head -10 myfile) <(tail -100 myfile) > anotherfile
>
> In Korn shell.

I was going to vote for Andreas' response as being the best.
... until I saw this one!

-am © 2002

Dan

unread,
Aug 27, 2002, 2:49:34 PM8/27/02
to

"Edel" <ekea...@ddsi.ie> wrote in message
news:397e7fa6.0208...@posting.google.com...

The other responders gave you the syntax for tail. If what you are saying
is for some reason your tail will not work with the correct options, you can
use sed to get specific lines from a file.


Oscar del Rio

unread,
Aug 27, 2002, 2:41:20 PM8/27/02
to

Anthony Mandic wrote:

>>$ cat <(head -10 myfile) <(tail -100 myfile) > anotherfile
>>
>>In Korn shell.
>
> I was going to vote for Andreas' response as being the best.
> ... until I saw this one!


Here's my entry, hope not too late (what's the prize?) :-)

$ (head -10 myfile; tail -100 myfile) > anotherfile

in any shell

Barry Margolin

unread,
Aug 27, 2002, 3:02:43 PM8/27/02
to
In article <397e7fa6.0208...@posting.google.com>,

Edel <ekea...@ddsi.ie> wrote:
>I have a unix file 7.5M in size. I want to take the first 10 lines and
>the last 100 lines and put these into another file without losing any
>spaces.
>I can't view the file using vi as the file is too big and when I use
>the tail command, it will not get the last 100 lines - it only
>retrieves the last 25 lines approx.

Many versions of tail have a limit on the number of lines they can handle,
but I'm pretty sure this limit is usually larger than 100. Why don't you
show what you tried?

How long are the lines in the file? Tail may have problems with really
long lines, too.

If you can, use GNU tail. It's not likely to have any arbitrary limits.

--
Barry Margolin, bar...@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

0 new messages