output only numbers from mixed string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting output only numbers from mixed string
# 8  
Old 08-29-2006
ah solvered already, wouldn't read about it!

echo "abc12345" | tr -cd [a-z]+[A-Z]

thanks anyway
# 9  
Old 08-29-2006
may be this

Code:
echo "abc12FG345" | tr -cd [:alpha:]

--this may also work. I am not at my system. So cant test it.Check this link -
tr command
# 10  
Old 08-29-2006
I'm confused here... do you want to retain the alphabets or remove them in that example?
I'll give a couple of examples:
Code:
# echo abc123$%^|tr -cd [:alpha:]
abc#
# echo abc123$%^|tr -d [:alpha:]
123$%^
#

So what the first tr does is delete all elements (-d) that are in the complement set (-c) as that of alpha. This means that anything that is not an alphabet (upper/lower case) will be removed. In the second, no complements are used, so tr will delete all elements that are in the alpha set.
# 11  
Old 08-29-2006
i think

I think, in the first part of the question, it was to retain only numbers and then nortypig wanted to retain 2 sets of patterns - [a-z]+[A-Z], both uppercase and lowercase letters. That was my understanding..
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