output only numbers from mixed string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting output only numbers from mixed string
# 1  
Old 08-29-2006
output only numbers from mixed string

it must be late because I'm sure this is an easy task with grep sed or awk

string would be anything mixing numbers letters and ) ( =

output I need is just the numbers... but I just can't seem to get it to work.

Any tips would be great Smilie
# 2  
Old 08-29-2006
Code:
echo '12sj5(+_=23' | sed 's/[^0-9]//g'

# 3  
Old 08-29-2006
ahh thanks, I spent a few hours trying to get this to work and even had a similar line in there at one time experimenting. Thanks heaps.
# 4  
Old 08-29-2006
try tr

Code:
echo "abc12345" | tr -cd [0-9]

--not tested though..

Last edited by ranj@chn; 08-29-2006 at 08:49 AM.. Reason: add comments
# 5  
Old 08-29-2006
tr is quite good, do a man on tr and you can do heaps...
# echo "abcd1234" | tr -d [:digit:]
# 1234
You can check for control chars the lot.
# 6  
Old 08-29-2006
Quote:
Originally Posted by Andrek
tr is quite good, do a man on tr and you can do heaps...
# echo "abcd1234" | tr -d [:digit:]
# 1234
You can check for control chars the lot.
Actually the output of that would be abcd, not 1234
# 7  
Old 08-29-2006
Ranj, I am curious. How could I specify for example...

Code:
echo "abc12FG345" | tr -cd [a-z][A-Z]

if I wanted to not delete more than one range, I've played with this a bit but can't find the syntax for such a thing.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Merge two text files by two fields and mixed output

Hello, I'm back again looking for your precious help- This time I need to merge two text files with matching two fields, output only common records with mixed output. Let's look at the example: FILE1 56153;AAA0708;3;TEST1TEST1; 89014;BBB0708;3;TEST2TEST2; 89014;BBB0708;4;TEST3TEST3; ... (7 Replies)
Discussion started by: emare
7 Replies

2. Shell Programming and Scripting

Sorting mixed numbers and letters

Hello, I have a file such as this: chr1 chr2 chr1 chr2 chr3 chr10 chr4 chr5 chrz chr1AI want to sort it, I use this command: sort -k1 -th -n testfilebut I get this output, how can I fix this? chr1 chr1 chr10 chr1A chr2 chr2 (3 Replies)
Discussion started by: Homa
3 Replies

3. Shell Programming and Scripting

awk - output-data always two numbers

Hi, my data is like the subsequent snipped. Fieldseperator is TAB. I can work the data well with awk, but the missing zero-numbers at the days column, for the days smaller 10 and the full hour-minutes i cant handle in the output. 2012 7 1 8 40 249.463 245.01 5.70448 6.11388 6.22125... (2 Replies)
Discussion started by: IMPe
2 Replies

4. Shell Programming and Scripting

parse a mixed alphanumeric string from within a string

Hi, I would like to be able to parse out a substring matching a basic pattern, which is a character followed by 3 or 4 digits (for example S1234 out of a larger string). The main string would just be a filename, like Thisis__the FileName_S1234_ToParse.txt. The filename isn't fixed, but the... (2 Replies)
Discussion started by: keaneMB
2 Replies

5. Shell Programming and Scripting

add numbers to the output based on +/-

Add 35 to the 3rd col (12000) in input if it is "+" and it will be 12035 in output. Some thing like awk '{if ($3==+) print $2,$3,$3+35,$1 else print $2,$3-35,$3,$1}' + abc1 12000 - abc2 10000 + xyz1 11111 - vbcx 20036 + xy_z 33333 output abc1 ... (2 Replies)
Discussion started by: ruby_sgp
2 Replies

6. Shell Programming and Scripting

awk: round output or delimit output of arithmatic string

I have a file with the following content. > cat /tmp/internetusage.txt 6709.296322 30000 2/7/2010 0.00I am using the following awk command to calculate a percentage from field 1 and 2 from the file. awk '{ print $1/$2*100 }' /tmp/internetusage.txt This outputs the value "22.3643" as a... (1 Reply)
Discussion started by: jelloir
1 Replies

7. Shell Programming and Scripting

sed output with numbers

I get the same value "chinchwad" for the following 3 statements. echo "ABCDchinchwad18-Mar-2010-11.sql.zip" | sed -r 's/(+)(+)(.*)/\2/' echo "ABCDchinchwadII18-Mar-2010-11.sql.zip" | sed -r 's/(+)(+)(.*)/\2/' echo "ABCDchinchwad918-Mar-2010-11.sql.zip" | sed -r 's/(+)(+)(.*)/\2/' I expect:... (4 Replies)
Discussion started by: shantanuo
4 Replies

8. 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

9. Shell Programming and Scripting

How do i get numbers from a string?

Hi... I'm new here and i have a Q... How do i get only the number from a string? like from "rlvol11" i want to get 11 or from "lvol4" i want to get 4 what commands should i use at my script? thanx 4 the help! Eliraz. (13 Replies)
Discussion started by: eliraza6
13 Replies

10. Shell Programming and Scripting

Sub. numbers in column of output with If

This is my script. I am pulling the status of some hard where, but the status is in numerical form. The number 4 means Major and the 5 means Critical. In my script I would like to show the alarm type in aplha rather than numeric form. So if instead of seeing a 4 or 5 you would see MAjor or... (11 Replies)
Discussion started by: ja156194
11 Replies
Login or Register to Ask a Question