[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: removing lines from a file



On Saturday 02 November 2002 02:29 pm, Jason Pepas wrote:
> On Saturday 02 November 2002 02:19 pm, Lance Hoffmeyer wrote:
> > I know this has come up before but what is the best
> > way to remove lines 5-10 and lines 16-20 from
> > a file using the console and a batch file?
> >
> > Lance
>
> you could use wc to get the total number of lines, and then use head and
> tail to grab the sections you want (try piping them into each other to get
> subsections)
>
> -jason pepas

specifically, this should do it:

	#!/bin/sh
	head -n 4 $1
	cat $1 | head -n 15 | tail -n 5
	lines=`wc -l $1 | cut -d ' ' -f 6`
	tail -n `expr $lines - 20` $1

use it like this:

	./chop.sh in.txt > out.txt

-jason pepas



Reply to: