LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   extraction of sting (https://www.linuxquestions.org/questions/linux-newbie-8/extraction-of-sting-894453/)

xerox 07-29-2011 05:11 AM

extraction of sting
 
Given the input :
busybox-1.11.1-1_WR3.0bg.armv6jel_vfp.rpm
i want to extract what comes before ".rpm"
i.e, busybox-1.11.1-1_WR3.0bg.armv6jel_vfp

acid_kewpie 07-29-2011 05:36 AM

if that's a proper description of the issue, i.e. remove the .rpm suffix, just use "basename $STRING .rpm"

xerox 07-29-2011 05:49 AM

suppose my input is like this
busybox-1.11.1-1_WR3.0bg.armv6jel_vfp.rpm = 1.1111.2l2

i want to extract
busybox-1.11.1-1_WR3.0bg.armv6jel_vfp

from the given input line

given characters may follow ".rpm"

I dont want anything after ".rpm"

using sed or awk command

crts 07-29-2011 05:49 AM

Or, if you are using bash then you could use bash's own String manipulation mechanism, e.g.
Code:

echo ${STRING%.rpm*}


[edit]: Just saw your latest post. So is it correct to assume that this line is inside a file and not stored in a variable?
In this case:
Code:

sed 's/\.rpm.*$//' inputfile
You might have to provide a representative sample of you input data.

xerox 07-29-2011 06:02 AM

Yes...perfect ...it worked just as i wanted it to......:D

Thanks a zillion....


All times are GMT -5. The time now is 04:36 PM.