LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 04-13-2011, 05:02 PM   #1
anie
LQ Newbie
 
Registered: Apr 2011
Posts: 3

Rep: Reputation: 0
Perl Question: remove a part of string unit1/U800/o


In a file,
I need to remove a part of string: /o

string:

$p = unit1/U800/o

or

the string can be

$p = ghsunit2/U801/d2

here I need to remove /d2

So, I need to remove everything after when I get last /

Any help would be appreciated.
 
Old 04-13-2011, 05:12 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by anie View Post
In a file,
I need to remove a part of string: /o

string:

$p = unit1/U800/o

or

the string can be

$p = ghsunit2/U801/d2

here I need to remove /d2

So, I need to remove everything after when I get last /

Any help would be appreciated.

Hi, welcome to LQ!

Code:
$p =~ s@/[^/]+$@@;

Moving this to programming as it's not a linux-question.



Cheers,
Tink
 
Old 04-13-2011, 05:23 PM   #3
anie
LQ Newbie
 
Registered: Apr 2011
Posts: 3

Original Poster
Rep: Reputation: 0
@Tink: Thank you for your reply.

But, the string can be:

$p = ghsunit2/mcr/gths21/U801/d2


or

$p = ghsunit2/mcr/gths21/o
 
Old 04-13-2011, 05:32 PM   #4
anie
LQ Newbie
 
Registered: Apr 2011
Posts: 3

Original Poster
Rep: Reputation: 0
Thank you for the solution.

I got it.
 
Old 04-13-2011, 05:44 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Cool ... can you mark your thread as solved, please? =)


Cheers,
Tink
 
  


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
[SOLVED] get part of a string in bash xeon123 Linux - Newbie 3 03-10-2011 10:04 AM
[SOLVED] extract part of string himu3118 Programming 4 05-07-2010 07:13 AM
[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
[perl]How to treat string like "a b" as a single string when split? john.daker Programming 21 06-01-2009 05:57 PM
remove part of string in bash script crewblunts Programming 2 03-16-2006 05:54 PM

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

All times are GMT -5. The time now is 08:18 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