The UNIX and Linux Forums  


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
last char from a string broli Shell Programming and Scripting 6 12-07-2007 08:02 PM
replacing char with string phani_sree High Level Programming 1 11-20-2006 08:57 AM
string of 7 char length always... thanuman UNIX for Dummies Questions & Answers 3 04-12-2005 01:51 PM
Number of specific char in a string. gio123bg Shell Programming and Scripting 7 12-19-2003 02:27 PM

Closed Thread
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 07-16-2008
netbanker netbanker is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 8
how to get number char from a string

for example:

i hav a string like :

/rmsprd/arch01/rmsprd/rmsprdarch72736.log

how I can extract

my_num=72736?

I know I can

echo "/rmsprd/arch01/rmsprd/rmsprdarch72736.log" | tr "/" " " | awk '{ print $4 }' to get rmsprdarch72736.log
  #2 (permalink)  
Old 07-16-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Cool will it always be in same format?


Code:
> echo "/rmsprd/arch01/rmsprd/rmsprdarch72736.log" | cut -d"/" -f5 | cut -d"." -f1
rmsprdarch72736

if you know it will always be ten characters (rmsprdarch), then

Code:
> echo "/rmsprd/arch01/rmsprd/rmsprdarch72736.log" | cut -d"/" -f5 | cut -d"." -f1 | cut -c11-
72736

  #3 (permalink)  
Old 07-16-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,327
Something like:


Code:
my_num=`echo $string | sed 's/.*[a-z]\([0-9].*\)\..*/\1/'`

Regards
  #4 (permalink)  
Old 07-16-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,934
If you are using ksh93 you do not need to invoke external utilities like cut or sed. The following will work

Code:
$ str="/rmsprd/arch01/rmsprd/rmsprdarch72736.log"
$ print $str
/rmsprd/arch01/rmsprd/rmsprdarch72736.log
$ print ${str/*([[:print:]])({5}(\d)).log/\2}
72736
$

  #5 (permalink)  
Old 07-16-2008
pramodmc pramodmc is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 3
echo "/rmsprd/arch01/rmsprd/rmsprdarch72736.log" | cut -d"/" -f5 | cut -d"." -f1|tr -d [:alpha:]
Closed Thread

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 12:48 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