Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


Search this Thread
Old 12-16-2007, 04:04 AM   #1
LQ Newbie
Registered: Nov 2007
Posts: 20

Rep: Reputation: 0
Using Delimiters to get the end of the string


Im want to extract a part of a word. Say for example, in
abcd_def_fgh i want abcd_def. That is except the text occuring after the the last delimiter(_).Also the length and the number of delimiters are not fixed.

Some more examples:
blah_blah_blah_blah ->blah_blah_blah

Any ideas on how this can be done?

Old 12-16-2007, 04:23 AM   #2
Senior Member
Registered: Aug 2006
Posts: 2,696
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
in bash
# echo $s
# echo ${s%_*}
Old 12-16-2007, 06:01 AM   #3
LQ Newbie
Registered: Nov 2007
Posts: 20

Original Poster
Rep: Reputation: 0
Thanks man
Old 12-16-2007, 06:15 AM   #4
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
In Perl:
my $s = "blah_blah_blah_blah_set";
$s =~ s/_[^_]*$//;
print "$s\n";


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
Append string to end of file name chellemybelle Linux - Newbie 4 11-26-2007 07:17 PM
remove the 'd' character from the end of string powah Programming 6 11-08-2007 07:00 AM
Append variable string(s) at end of each line schaganti Linux - Newbie 2 10-19-2007 01:31 PM
How can I check if there slash in the end of string in bash if? nadavvin Programming 5 01-27-2007 02:41 AM
Parse --static string no delimiters DaFrEQ Programming 2 04-08-2005 02:06 PM

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

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