Results 1 to 4 of 4
hi, I want find numbers in string. its simple task, but I need to find numbers bigger then 9 too. my english is quite bad so I give you example ...
- 11-02-2011 #1Just Joined!
- Join Date
- Nov 2011
- Posts
- 2
how to find numbers in string
hi, I want find numbers in string. its simple task, but I need to find numbers bigger then 9 too. my english is quite bad so I give you example for understand: from string "a20b1++q140" script find numbers x[0]=20 x[1]=1 x[2]=140. can somebody help me with that?
- 11-02-2011 #2
Hi Giuseppe,
it would look to me that you've got the numbers already parsed. But what do you want to do with them?
- 11-02-2011 #3Just Joined!
- Join Date
- Nov 2011
- Posts
- 2
thanks for answer
no, that was only example what script would have to do, but I have problem to code script for it. sorry, I wrote it bad..
- 11-02-2011 #4Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
I'd use bash built-in arrays and sed, e.g.:
Code:#!/bin/bash declare -a array string="foo1bar2shite3blah4" array=($(echo $string|sed -e 's/[^0-9]/ /g')) echo Number of numbers found: ${#array[*]} echo "first number: ${array[0]}" echo "second number: ${array[1]}" echo "third number: ${array[2]}" echo "fourth number: ${array[3]}"


Reply With Quote