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

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
splitting the files sharif UNIX for Advanced & Expert Users 9 02-13-2008 06:38 AM
Splitting of a file zeusss Shell Programming and Scripting 4 12-03-2007 02:40 AM
Splitting a txt file mohdtausifsh UNIX for Dummies Questions & Answers 6 10-04-2006 03:19 AM
How to concatenate two strings or several strings into one string in B-shell? fontana Shell Programming and Scripting 2 08-26-2005 12:58 PM
file splitting praveen.pinto UNIX for Advanced & Expert Users 2 02-10-2005 09:54 AM

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 02-11-2004
bensky bensky is offline
Registered User
  
 

Join Date: Feb 2002
Posts: 23
splitting strings

Hi you,

I have the following problem:

I have a string like the followings: '166Mhz' or '128MB' or '300sec' or ...
What I want to do is, I want to split the strings in a part with the numbers and a part with letters.
Since the strings are not allway three digits and than text i couldn't do this with a simple cut.

How to solve this. I suggest there should be an easy way to do this with awk or so, but I am just to stupid to do this.

Thanks for any help.

Ben Sky
  #2 (permalink)  
Old 02-11-2004
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
Separate Number from String

Perderabo just posted a solution to a problem very similar to this...

To get the beginning part (with the numbers) use:

a="166Mhz"; echo ${a%%[A-Za-z]*}

To get the ending part (with the letters) use:

a="166Mhz"; echo ${a##*[0-9]}
  #3 (permalink)  
Old 02-11-2004
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
  
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
Code:
if (/(\d+)(\w+)/) { print "Digits: $1\tLetters:$2\n" };
thats what you would use in perl.
  #4 (permalink)  
Old 02-11-2004
bensky bensky is offline
Registered User
  
 

Join Date: Feb 2002
Posts: 23
Thanks alot, You are the best, I didn't know this trick, but it works great!
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 10:49 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