LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-07-2010, 06:50 AM   #1
himu3118
Member
 
Registered: Mar 2010
Posts: 35

Rep: Reputation: 15
extract part of string


i have string like abc0912981-92191.c

i want to extract part between - and . i.e. 92191. the number after abc 0912981 can vary..

Any ideas much appreciated..
 
Old 05-07-2010, 06:58 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391
Hi,

echo $string | sed 's/.*-\(.*\).c/\1/'

Hope this helps.
 
Old 05-07-2010, 07:03 AM   #3
himu3118
Member
 
Registered: Mar 2010
Posts: 35

Original Poster
Rep: Reputation: 15
thanks for the help. its working.

can you please suggest me some links from which i could learn about regular expressions..
 
Old 05-07-2010, 07:10 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391Reputation: 2391
Hi,

regular expressions aren't the important part in this example (only .* is used). Back referencing is the important part.

All between \( and \) in the search part can be represented as \1 in the replace part.

GNU Sed manual
Sed manual
Sed faq 3

Hope this is what you are looking for.

Last edited by druuna; 05-07-2010 at 07:14 AM.
 
Old 05-07-2010, 07:13 AM   #5
himu3118
Member
 
Registered: Mar 2010
Posts: 35

Original Poster
Rep: Reputation: 15
thanx agian..

i'll definitely go through these links..
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] C - How to put a specific arbitrary part of a string into it's own string? golmschenk Programming 9 04-19-2010 08:27 PM
Awk - Extract a particular string thomchad Programming 17 04-04-2010 02:55 AM
extract substring from string in C baddah Programming 6 02-02-2010 04:22 AM
Extract value from string ewingtux Programming 1 12-27-2008 07:19 PM
Extract part of a string steven.c.banks Linux - General 7 05-07-2008 07:18 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:45 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration