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 george@georgetoft.com:
>
> > -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: jd@twingeckos.com
> http://www.twingeckos.com
> phone/fax: 480.344.2640
>
> ---------------------------------------------------
> PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
> To subscribe, unsubscribe, or to change you mail settings:
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
---------------------------------------------------
PLUG-discuss mailing list -
PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change you mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss