LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-29-2011, 05:11 AM   #1
xerox
Member
 
Registered: Mar 2011
Posts: 43

Rep: Reputation: 0
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
 
Old 07-29-2011, 05:36 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
if that's a proper description of the issue, i.e. remove the .rpm suffix, just use "basename $STRING .rpm"
 
Old 07-29-2011, 05:49 AM   #3
xerox
Member
 
Registered: Mar 2011
Posts: 43

Original Poster
Rep: Reputation: 0
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
 
Old 07-29-2011, 05:49 AM   #4
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
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.

Last edited by crts; 07-29-2011 at 05:53 AM.
 
1 members found this post helpful.
Old 07-29-2011, 06:02 AM   #5
xerox
Member
 
Registered: Mar 2011
Posts: 43

Original Poster
Rep: Reputation: 0
Yes...perfect ...it worked just as i wanted it to......

Thanks a zillion....
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[bash] sting as variable dzaku Programming 6 06-27-2011 09:31 AM
Where c++ STL sting have memory leak or Not ? kbarani Programming 0 08-27-2009 04:41 AM
Help with Conversion from Sting to Char Diederick Programming 2 11-30-2005 08:00 AM
cast from sting to int in Visual C++ Diederick Programming 3 11-29-2005 08:27 AM
Sting.h alaios Programming 2 08-21-2005 04:35 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration