The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
get partial numbers from a string jimmy_y Shell Programming and Scripting 1 08-24-2009 05:35 PM
[Perl] Find one string, change another string. ejdv Shell Programming and Scripting 5 06-10-2009 03:44 AM
delete line from file if successful partial string found cronjob78 UNIX for Advanced & Expert Users 7 05-14-2009 02:35 AM
Perl: Better way to match string within a string Juha Shell Programming and Scripting 3 01-11-2009 10:09 PM
PerL Reverse the string. email-lalit Shell Programming and Scripting 3 07-18-2008 07:22 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-25-2009
jimmy_y jimmy_y is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 94
perl get partial string of a string

Hi All,

I have:
Code:
$d = "12.02222222222";
$d =~ s/(.*).(.*)/$1/e;
The output should be just 12.
Please guide me my expression wrong.

Thanks
  #2 (permalink)  
Old 08-25-2009
durden_tyler's Avatar
durden_tyler durden_tyler is online now Forum Advisor  
Registered User
  
 

Join Date: Apr 2009
Posts: 530
Code:
$ 
$ perl -le '$d = "12.02222222222"; $output=sprintf("%d",$d); print $output'
12
$
tyler_durden
Bits Awarded / Charged to durden_tyler for this Post
Date User Comment Amount
08-25-2009 jimmy_y N/A 200
  #3 (permalink)  
Old 08-25-2009
agn agn is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 172
Change

Code:
$d =~ s/(.*).(.*)/$1/e;
to

Code:
$d =~ s/(.*)\.(.*)/$1/e;
Bits Awarded / Charged to agn for this Post
Date User Comment Amount
08-25-2009 jimmy_y N/A 200
  #4 (permalink)  
Old 08-25-2009
jimmy_y jimmy_y is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 94
Thanks tyler, tyler. It works

If i have a string
$val=14480 # This is seconds.

How would i make it into 040102, hhmmss, how should i use regular express to do .

Thanks
  #5 (permalink)  
Old 08-25-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,860
Regex can do a lot, but not that (and never were intended to [unless someone wants to prove me wrong])
Code:
perl -e '$val=14480; $hms=sprintf("%02d%02d%02d",int($val/3600),int($val%3600/60),int($val%60)); print $hms,"\n";'
040120
Bits Awarded / Charged to pludi for this Post
Date User Comment Amount
08-25-2009 jimmy_y N/A 500
  #6 (permalink)  
Old 08-25-2009
jimmy_y jimmy_y is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 94
Quote:
Originally Posted by pludi View Post
Regex can do a lot, but not that (and never were intended to [unless someone wants to prove me wrong])
Code:
perl -e '$val=14480; $hms=sprintf("%02d%02d%02d",int($val/3600),int($val%3600/60),int($val%60)); print $hms,"\n";'
040120
Thanks works.

---------- Post updated at 02:11 AM ---------- Previous update was at 02:08 AM ----------

Below is the finally code, hope this is the most simple method.
i have two date, i want to get the duration in to hhmmss format. Below is the working code.

Code:
$a = localtime(UnixDate(ParseDate("20090823 08:03:35"),"%s"));
$b = localtime(UnixDate(ParseDate("20090823 12:04:55"),"%s"));
$c = str2time($b)-str2time($a);
$hms=sprintf("%02d%02d%02d",int($c/3600),int($c%3600/60),int($c%60));
print $hms;
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:05 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0