Solved

shell scripting match leading numbers

Posted on 2011-09-13
1
304 Views
Last Modified: 2012-05-12
In shell scripting I need to yank out leading numbers,  in the examples host below I need it to match any leading numbers then stop whenever the next characters is not number.

example:

99-host-01.com
result I want:  99

1000-host.com
result I want: 1000

host999.com
result I want: nothing
0
Comment
Question by:phatbrain101
1 Comment
 
LVL 22

Accepted Solution

by:
pivar earned 250 total points
ID: 36532685
Hi,

How about? If it's from a file.

grep -o '^[0-9]*' filename

/peter
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Utilizing an array to gracefully append to a list of EmailAddresses
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now