Re: Reading a particular line in a file

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: George Toft
Date:  
To: plug-discuss
Subject: Re: Reading a particular line in a file
INDEX=22
sed -n "${INDEX}p" filename

In this case, the curly braces are used to define the variable name in
the shell. The shell requires this as without it, it would see "INDEXp"
as the name and not do what you want. sed needs a range/number before
the "p"

--
George Toft
CISSP, MSIS
CTO/Computer Security
AGD,LLC
www.agdllc.com
623-203-1760


JD Austin wrote:
>
> Quoting :
>
> > -To print one line of text:
> > sed -n "${INDEX}p" filename
> > (where INDEX is the line # or numbers)
> >
> > George Toft
> Thats a great one!
>
> I'm always amazed what can be done using head, tail, grep , sed and awk.
>
> I tried your example and couldnt get it to work, how do you specify INDEX?
> I tried
> sed -n "${22}p" filename (listed whole file)
> sed -n "${cat testfile}p" filename (bad substitution)
> sed -n "${22,23,24}p" filename (bad substitution)
> sed -n "${22 23 24}p" filename (bad substitution)
>
> This works:
> sed -n "22p" filename
>
> JD
> >
> >
> > > Is there a command line argument that lets you grab a particular line from
> > > from a text file in Linux or Unix?
> > >
> > > Thanks,
> > >
> > > Ben
> > >
>
> --
> JD Austin
> Twin Geckos Technology Services LLC
> email:
> http://www.twingeckos.com
> phone/fax: 480.344.2640
>
> ---------------------------------------------------
> PLUG-discuss mailing list -
> To subscribe, unsubscribe, or to change you mail settings:
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss

---------------------------------------------------
PLUG-discuss mailing list -
To subscribe, unsubscribe, or to change you mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss