Remove Last Line Of File

Posted on 2006-05-05
Last Modified: 2010-04-21
Hi Experts

I've a 10Gb UNIX text file and I need to remove the very last line.
Can anyone help me out?
Question by:stummj
    LVL 84

    Expert Comment

    perl -MTie::File -e 'tie @array, 'Tie::File', shift or die $!; pop @array; untie @array' file

    Author Comment

    Cool - but whats the syntax I need to use? which bits do I need to replace with my filename and do I need a redirect to a new file or will it just strip off the last line in the existing file?
    LVL 43

    Accepted Solution

    head -n -1 filename > new.filename # would also do with less memory consumption, but will create new file.


    Author Comment

    Great! That will do nicely thanks.
    LVL 43

    Expert Comment

    But do try ozo's sollution - it's inplace sollution, hence may be better.
    perl -MTie::File -e 'tie @array, 'Tie::File', shift or die $!; pop @array; untie @array' FILENAME_HERE

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
    Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    This tutorial goes over how to archive and restore FreeBSD jails that are managed by ezjail.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now