On Sun, 28 Dec 2008 13:21:59 Erez D wrote:
>
> On Sun, Dec 28, 2008 at 12:00 AM, Oleg Goldshmidt wrote:
>
> > >>
> > >> $ basename ${foo/*input_/} .txt
> > >>
>
> this is a solution speceific to the .txt being preceided by the 000.
> (it will not work on path/input_000_xyz.txt).
>
> i just wanted to know if i can do that in one line in bash without any
> external programs (like sed )
> the answer is - it can't be done. that's good enough for me, i'll use a temp
> var and two lines.

It can be done with bash ONLY in 2 lines.

1st solution (simple extraction):
    FL=/GIBUY/abc_input_000_xyz.txt
    NUM=${FL:${#FL}-11:3}

2nd solution - use IFS to break the file name into parts:
    IFS="_."
    PRTS=($FL)         # you can use the file name directly
now you have the "000" in  "${PRTS[2]}"
you can check it with:
    echo "${PRTS[0]} ${PRTS[1]} ${PRTS[2]} ${PRTS[3]} ${PRTS[4]}"
    echo "${PRTS[2]}"

Ehud.


--
 Ehud Karni           Tel: +972-3-7966-561  /"\
 Mivtach - Simon      Fax: +972-3-7966-667  \ /  ASCII Ribbon Campaign
 Insurance agencies   (USA) voice mail and   X   Against   HTML   Mail
 http://www.mvs.co.il  FAX:  1-815-5509341  / \
 GnuPG: 98EA398D <http://www.keyserver.net/>    Better Safe Than Sorry

=================================================================
To unsubscribe, send mail to linux-il-requ...@cs.huji.ac.il with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail linux-il-requ...@cs.huji.ac.il

Reply via email to