[PLUG] How to pull out a particular line from a textfile
Colin Kuskie
ckuskie at dalsemi.com
Wed Sep 18 21:39:27 UTC 2002
On Wed, Sep 18, 2002 at 02:36:01PM -0700, Matt Alexander wrote:
> I've got a file and I want to write a script to pull out particular lines
> and save them in variables. Line 1 is always the email address and Line 2
> is always the subject, for example.
>
> #!/bin/bash
>
> EMAIL=`some magical way to pull out line 1 from a textfile`
> SUBJECT=`some magical way to pull out line 2 from a textfile`
>
>
> I assume there's a simple command to pull out a particular line from a
> textfile, but I can't think of anything right now.
I usually use perl:
perl -ne 'print if $. == 1' textfile
where $. is the current line number.
You can also use combinations of head and tail:
First line:
head -1
Second line:
head -2 | tail -1
Colin
More information about the PLUG
mailing list