On Fri, 9 Aug 2002, Paul Branston wrote:

> On Thu, Aug 08, 2002 at 11:40:32AM -0400, Michael C Tiernan wrote:
> > On Thursday 08 August 2002 08:59, Nick Lindsell said:
> >  > At 14:34 08/08/2002 +0200, you wrote:
> >  > > "File_21_05082002" and i would like to
> >  > > extract "21" from this.
> >  > >How can i do it with 'sed'?
> >  >
> >  > No need for sed, cut is simpler:-
> >  > $extract= echo "File_21_05082002"|cut -c 6-7
> >
> > Cut is easier for this problem but I'd modify it one bit....
> > $extract= `echo "File_21_05082002"|cut -d_ -f2`
> >
> > This assumes (*cough*) that you want the value between the two "_" characters.
> >
> > To answer your original question.....  In sed:
> > $extract=`echo $Fname | sed -e "s/^File_//" -e "s/_[0-9]*$//"`
> >
> > Should come very close to what you wanted (I think...)
>
> or in sed using 1 pattern match assuming File_ always comes before the
> digits and the end of the digits is a _ character.
>
>  echo "File_21_05082002"|sed -e 's/^File_\(.*\)_.*$/\1/'
>

Or just use shell globbing:

  orig="File_21_05082002"
  temp=${orig#*_}
  result=${temp%_*}
  echo $result

-- 
John Darrah (u05192)    | Dept: N/C Programming
Giddens Industries      | Ph: (425) 353-0405 #133
PO box 3190             | Ph: (206) 767-4212 #133
Everett  WA    98203    | Fx: (206) 764-9639



-- 
redhat-list mailing list
unsubscribe mailto:[EMAIL PROTECTED]?subject=unsubscribe
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to