LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 12-05-2007, 05:16 AM   #1
bharatbsharma
Member
 
Registered: Oct 2007
Posts: 33

Rep: Reputation: 15
string parsing using perl


Using perl i want to parse a string

My string is

UMS5.0/MTC/SHI/UDR/UMSV5.0Sh_DSR_UDR_06.db_ins: private_id = "usermtc@bbc.com";

i want a output (o/p)

UMS5.0/MTC/SHI/UDR/UMSV5.0Sh_DSR_UDR_06.db_ins

that is every character appearing from ":" to end of string have to be deleted.

How this can be done?
 
Old 12-05-2007, 06:04 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Code:
my $str = 'UMS5.0/MTC/SHI/UDR/UMSV5.0Sh_DSR_UDR_06.db_ins: private_id = "usermtc@bbc.com";';

print "before: $str\n";
$str =~ s/:.*$//;
print "after:  $str\n";
output:
Code:
before: UMS5.0/MTC/SHI/UDR/UMSV5.0Sh_DSR_UDR_06.db_ins: private_id = "usermtc@bbc.com";
after:  UMS5.0/MTC/SHI/UDR/UMSV5.0Sh_DSR_UDR_06.db_ins
You could also use split, like this:
Code:
$str = (split(":", $str))[0]
 
  


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
parsing a string from grep output in bash xpromisex Programming 2 11-12-2006 09:12 AM
(shell script) string parsing kuru Programming 4 09-12-2005 07:59 PM
Perl/regexp help... - query string parsing... lowpro2k3 Programming 4 05-11-2005 05:18 PM
parsing a user input string daphne19 Programming 1 04-22-2004 07:40 AM
Parsing a file for a string of text jamesmwlv Linux - General 2 12-02-2002 07:13 PM

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

All times are GMT -5. The time now is 03:41 AM.

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