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/' -- redhat-list mailing list unsubscribe mailto:[EMAIL PROTECTED]?subject=unsubscribe https://listman.redhat.com/mailman/listinfo/redhat-list