Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 8 Dec 2003 22:14:58 -0500
From:      William O'Higgins <william.ohiggins@utoronto.ca>
To:        freebsd-questions <freebsd-questions@freebsd.org>
Subject:   Re: a technical how to
Message-ID:  <20031209031458.GA2922@sillyrabbi.dyndns.org>

next in thread | raw e-mail | index | archive | help
On Mon, Dec 08, 2003 at 05:51:25PM -0800, homeyra g wrote:

>Here is the question: How to truncate a file from the
>begining to a certain point in the file?

You can do this in vi.  If you are trying to keep only the beginning,
you'd do this, where ++ is the first line you don't want:

:++,$d

If you only want the chunk at the end there are a couple of good ways:

:0,++-1d

or, if you want to keep the original file:

:++-1,$w newfile

Where newfile is the file name you want to keep your output in.

vi does a whole lot of fine things, and because it is nearly ubiquitous
in UNIX it may be worth using for such things.

If you want to do this from the command line you can do so with ex
scripts.  This is the "use vi for all text processing" approach.  Perl,
sed, awk, shell scripting; they'll all do the same job.  Pick a tool and
you'll get a lot of mileage out of it.  Have fun.
-- 

yours,

William



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20031209031458.GA2922>