wanted: utility to extract lines by line-no.

Michael Morrell morrell at hpsal2.HP.COM
Fri Apr 8 07:04:15 AEST 1988


> Does anyone know of a utility which will extract the nth line of a
> file?  I can easily write one but then I thought a general case
> utility might exist.  The utility could have the following
> description:
>
>	extract line-no [files]
>
>	Extract a specified line number, range of lines, or
>	series of lines from stdin or a series of files.
>
>
> Thanks in advance,
> Jeremy Uejio (pronounced 'oo-ay-joe')
> uejio at lll-lcc.llnl.gov
----------

Try using "sed".

  sed -n a,bp file

will extract lines a thru b from "file".

To get a series of lines, use

  sed -n '1,3p;10,21p;33,40p' file

or

  sed -n -e 1,3p -e 10,21p -e 33,40p file


    Michael Morrell



More information about the Comp.unix.questions mailing list