Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 9 Dec 2003 12:56:39 -0500
From:      Charles Swiger <cswiger@mac.com>
To:        homeyra g <homeyra_s@yahoo.com>
Cc:        freebsd-questions@FreeBSD.org
Subject:   Re: a technical how to
Message-ID:  <09F412E2-2A71-11D8-A16D-003065A20588@mac.com>
In-Reply-To: <20031209015125.74977.qmail@web14806.mail.yahoo.com>
References:  <20031209015125.74977.qmail@web14806.mail.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Dec 8, 2003, at 8:51 PM, homeyra g wrote:
> Here is the question: How to truncate a file from the
> begining to a certain point in the file?

The question is whether this file is ASCII text so line-based tools 
(such as tail) work, or whether you are truncating a binary file, in 
which case "split -b" is probably a better bet.

If you've got a logfile named /var/log/messages, and you want to 
truncate that to the last 100 lines:

mv /var/log/messages /var/log/messages.$$
tail -100 < /var/log/messages.$$ > /var/log/messages
rm -f /var/log/messages.$$

Use "wc -l" and "grep -n" to identify where to truncate the file if 
it's not a fixed size that you want...

-- 
-Chuck



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?09F412E2-2A71-11D8-A16D-003065A20588>