From owner-freebsd-questions@FreeBSD.ORG Thu Dec 11 14:45:09 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2EB2D16A4CE for ; Thu, 11 Dec 2003 14:45:09 -0800 (PST) Received: from mx1.mail.uk.clara.net (mx1.mail.uk.clara.net [195.8.69.186]) by mx1.FreeBSD.org (Postfix) with ESMTP id F32EF43DB3 for ; Thu, 11 Dec 2003 14:43:52 -0800 (PST) (envelope-from david@carter-hitchin.clara.co.uk) Received: from du-028-0106.claranet.co.uk ([195.8.84.106] helo=stoat.clara.net) by mx1.mail.uk.clara.net with esmtp (Exim 4.24) id 1AUZXB-0009L4-PH; Thu, 11 Dec 2003 22:43:50 +0000 Received: from stoat.clara.net (localhost [127.0.0.1]) by stoat.clara.net (8.12.8p2/8.12.8) with ESMTP id hBBMi65Z003825; Thu, 11 Dec 2003 22:44:07 GMT (envelope-from david@carter-hitchin.clara.co.uk) Received: from localhost (david@localhost)hBBMi6P8003822; Thu, 11 Dec 2003 22:44:06 GMT (envelope-from david@carter-hitchin.clara.co.uk) X-Authentication-Warning: stoat.clara.net: david owned process doing -bs Date: Thu, 11 Dec 2003 22:44:06 +0000 (GMT) From: David Carter-Hitchin X-X-Sender: david@stoat.clara.net To: Charles Swiger In-Reply-To: <09F412E2-2A71-11D8-A16D-003065A20588@mac.com> Message-ID: <20031211224316.F3802@stoat.clara.net> References: <20031209015125.74977.qmail@web14806.mail.yahoo.com> <09F412E2-2A71-11D8-A16D-003065A20588@mac.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: homeyra g cc: freebsd-questions@FreeBSD.org Subject: Re: a technical how to X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Dec 2003 22:45:09 -0000 Hiya, no-one has mentioned 'head' yet: head -100 file > newfile to save the first 100 lines of file into newfile. You can also use a combination of head and tail to take a portion of the file, e.g: head -100 file | tail -3 > newfile to save off lines 98,99 and 100 of file into newfile. I've known this to be useful when trying to extract certain lines from mammoth files. If, by "a certain point" you meant, for example, up to some general regex then you could employ some perl: cat file | perl -e 'while (<>) { exit if /REGEX/; print }' > newfile I know you can do similar things in sed and awk, but I don't know the syntax off the top of my head, and don't have my notes to hand. David On Tue, 9 Dec 2003, Charles Swiger wrote: > 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 > > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org" > >