extracting numbers from strings


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extracting numbers from strings
# 1  
Old 05-26-2008
extracting numbers from strings

Hello all,

I am being dumb with this and I know there is a simple solution.

I have a file with the follwing lines

Code:
 bc stuff (more)...............123
 bc stuffagain (moretoo)............0
 bc stuffyetagain (morehere)......34
 failed L3 thing..............1
 failed this status.............24
 failed that status.............253
 failed some kind of check........0

I want to pull the numbers off the end of the lines. I can use cut but that is not very robust. I have been using sed but cannot get it to work properly.

I don't think this is very hard. It's been a long day.

Thanks!

gobi

Last edited by Yogesh Sawant; 05-27-2008 at 03:01 AM.. Reason: added code tags
# 2  
Old 05-27-2008
If you just want to extract the last field:
Code:
$ sed -n 's/.*\.//;p' gobi.txt
or
$ awk 'BEGIN{FS="."} {print $NF}' gobi.txt

And to extract the digits:

Code:
$ sed 's/.*\.\.\([0-9]*\).*/\1/' gobi.txt

//Jadu
# 3  
Old 05-27-2008
yes thank you.

I left out the \.\. from the sed command. like I said its been a long day.

Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed extracting numbers

I have number 192.168.21.8. I want to extract from this number with sed 21 and 8 to variables a and b. Any Ideas? I did like 's/\(192.168.\)/ /' but its wrong :( (6 Replies)
Discussion started by: Natalie
6 Replies

2. Shell Programming and Scripting

Extracting numbers

Hi I am part of a academic organization and I want to send a fax to the students however there must be a quicker way to get the fax numbers extracted from the online forms they sent me. The file looks like this (numbers are fake in order to protect identity): Biochemistry Major Michael... (3 Replies)
Discussion started by: phil_heath
3 Replies

3. Shell Programming and Scripting

Extracting text between two constant strings

Hi All, I have a file whose common patter is like this: .I 1 .U 87049087 .S Some text here too .M This is a text .T Some another text here .P Name of the book .W Some lines of more text. This text needs to be extracted. .A more text goes here too .I 2 (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

4. Shell Programming and Scripting

Extracting strings from a log file.

I'm new to all this and I've been fiddling with this problem for HOURS and feel silly that I can't work it out! I have a .log file that VERY long and looks like this: 2011-08-31 10:03:34 SUESTART AG Amndmnt Client WebRequest DNU SUEEND Sequence: 600, 2011-08-31 10:03:34 SUESTART... (11 Replies)
Discussion started by: SusieSA
11 Replies

5. Shell Programming and Scripting

Extracting text between two strings

Hi, I've looked at a few existing posts on this, but they don't seem to work for my inputs. I have a text file where I want to extract all the text between two strings, every time that occurs. Eg my input file is Anna said that she would fetch the bucket. Anna and Ben moved the bucket.... (9 Replies)
Discussion started by: JamesForeman
9 Replies

6. UNIX for Dummies Questions & Answers

Extracting numbers from a String

Hi all, I'm a new programmer to shell script... and I have no idea how to use substring. I want to extract the numbers from the following string and place it into a variable: "170 unique conformations found" The numbers can be more than three digits depending on the case. I just want to... (10 Replies)
Discussion started by: ah7391
10 Replies

7. Shell Programming and Scripting

Extracting numbers from a string

Hello Everyone, i have quick question. I have file names like: bin_map300.asc and I would like to extract grid300. My approach so far: name=bin_map300.asc echo ${name%%.*} echo ${name##*_} I am stuck combining the two. Any help would be appreciated. (3 Replies)
Discussion started by: creamcheese
3 Replies

8. UNIX for Dummies Questions & Answers

Extracting numbers and multipling

Hi All, I have searched the forum but couldn't find exactly what I need. Hopefully someone may be able to help. I'm trying to put a script together that will extract numbers from a text file and multiply them by, for example 1.5 or 1.2 Sample file looks like this...... (1 Reply)
Discussion started by: speedfreak
1 Replies

9. Shell Programming and Scripting

Help with extracting strings from a file

I want to collect the characters from 1-10 and 20-30 from each line of the file and take them in a file in the following format.Can someone help me with this : string1,string2 string1,string2 string1,string2 : : : : (7 Replies)
Discussion started by: cmsdelhi
7 Replies

10. UNIX for Dummies Questions & Answers

Extracting strings

Hi, How do I extract the bytes size string from the ls -l command. (1 Reply)
Discussion started by: hugow
1 Replies
Login or Register to Ask a Question