Extraction of numbers from input


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Extraction of numbers from input
# 1  
Old 07-29-2011
Extraction of numbers from input

I have the following input:

xxxx-2.7.19_WR3

I have extract the following:

2.7.19

Can anyone suggest an awk or sed command to do the above...Smilie


another condition is
if the input is :

xxx-xxx_xxx-1.4-1_WR3.0bg.armv6jel_vfp

it shud still extract : 1.4-1

whenever "-" is followed by numbers, it should be extracted till "_WR3"
# 2  
Old 07-29-2011
can you give us real sample input (rather than xxxx charachers) ?
# 3  
Old 07-29-2011
input: python-2.5.1-26_WR3.0bg.armv6jel_vfp

expected output: 2.5.1-26


input: activemq-cpp-library-3.0.1-1_WR3.0bg.armv6jel_vfp


expected output: 3.0.1-1
# 4  
Old 07-29-2011
Its not optimum code i know but try this mate:

Code:
echo "python-2.5.1-26_WR3.0bg.armv6jel_vfp" |
sed 's#\([A-Za-z]*\)-\([0-9]\.[0-9]\.[0-9]-[0-9][0-9]*\)_\([A-Za-z]*\)#\2#'

regards

Last edited by EAGL€; 07-29-2011 at 05:06 AM.. Reason: syntax
# 5  
Old 07-29-2011
Try:
Code:
sed '/^[^0-9]*\([0-9][0-9.-]*\).*$/ s//\1/'

This User Gave Thanks to yazu For This Post:
# 6  
Old 07-29-2011
Or try..
Code:
echo 'python-2.5.1-26_WR3.0bg.armv6jel_vfp'| sed 's/^[^0-9]*-\([0-9][^_]*\)_.*/\1/'
echo 'activemq-cpp-library-3.0.1-1_WR3.0bg.armv6jel_vfp' | sed 's/^[^0-9]*-\([0-9][^_]*\)_.*/\1/'

This User Gave Thanks to michaelrozar17 For This Post:
# 7  
Old 07-29-2011
Quote:
Originally Posted by michaelrozar17
Or try..
Code:
echo 'python-2.5.1-26_WR3.0bg.armv6jel_vfp'| sed 's/^[^0-9]*-\([0-9][^_]*\)_.*/\1/'
echo 'activemq-cpp-library-3.0.1-1_WR3.0bg.armv6jel_vfp' | sed 's/^[^0-9]*-\([0-9][^_]*\)_.*/\1/'

What does the underscore do in this part of code can you explain Michael?
Code:
\([0-9][^_]*\)

thanks in advance
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Decimal numbers and letters in the same collums: round numbers

Hi! I found and then adapt the code for my pipeline... awk -F"," -vOFS="," '{printf "%0.2f %0.f\n",$2,$4}' xxx > yyy I add -F"," -vOFS="," (for input and output as csv file) and I change the columns and the number of decimal... It works but I have also some problems... here my columns ... (7 Replies)
Discussion started by: echo manolis
7 Replies

2. Shell Programming and Scripting

Reducing the decimal points of numbers (3d coordinates) in a file; how to input data to e.g. Python

I have a file full of coordinates of the form: 37.68899917602539 58.07500076293945 57.79100036621094 The numbers don't always have the same number of decimal points. I need to reduce the decimal points of all the numbers (there are 128 rows of 3 numbers) to 2. I have tried to do this... (2 Replies)
Discussion started by: crunchgargoyle
2 Replies

3. Shell Programming and Scripting

input of two numbers in the middle of the script

Hi, My script ask for the input of two numbers in the middle of it. I would like to know how to indicate this two numbers when I submit the script. thanks for any help, jalves (4 Replies)
Discussion started by: jalves
4 Replies

4. Shell Programming and Scripting

the smallest number from 90% of highest numbers from all numbers in file

Hello All, I am having problem to find what is the smallest number from 90% of highest numbers from all numbers in file. I am having file with thousands of lines and hundreds of columns. I am familiar mainly with bash but I am open to whatever suggestion witch will lead to the solutions. If I... (11 Replies)
Discussion started by: Apfik
11 Replies

5. Shell Programming and Scripting

Constructing numbers from input lines

I have a file with the information shown and I want to capture the entry having the rgdt tag and taking the value (the location of the represents the decimal point, for example 0p50 represents 0.50) I then want to divide the number at the end of each line by the value 0.50 I want to do... (7 Replies)
Discussion started by: kristinu
7 Replies

6. UNIX for Dummies Questions & Answers

Negative Numbers for input parameters.

Hello, I have a command that I need to supply a negative number as a parameter; how do I do this? I have tried giving it with double quotes, "", but no avail. Thanks, Gussi (3 Replies)
Discussion started by: Gussifinknottle
3 Replies

7. Shell Programming and Scripting

read numbers from file and output which numbers belongs to which range

Howdy experts, We have some ranges of number which belongs to particual group as below. GroupNo StartRange EndRange Group0125 935300 935399 Group2006 935400 935476 937430 937459 Group0324 935477 935549 ... (6 Replies)
Discussion started by: thepurple
6 Replies

8. Shell Programming and Scripting

String extraction from user input - sh

Hi, I have a shell script to build components of a product. The follow snippet will explain what I am doing. # !/bin/sh for choice in "$@" ; do case $choice in "o") echo "Calling $choice" ; o ;; "i") echo... (8 Replies)
Discussion started by: vino
8 Replies

9. Shell Programming and Scripting

Accept user input - only numbers

I have a situation where I want the user to enter only numbers in response to a READ command. I have some validation to restrict the number to be between 1 and 12, but if the user type in some characters the script echoes some error message and goes to the next command. Below is a snippet of the... (1 Reply)
Discussion started by: pvar
1 Replies

10. Shell Programming and Scripting

Is there any way to makesure that the input from the user is all numbers?

Is there any way to makesure that the input from the user is all numbers? thankz (5 Replies)
Discussion started by: XXXXXXXXXX
5 Replies
Login or Register to Ask a Question