sed command, look for numbers following letters

If I have a set of strings,
C21
F231
H42
1C10
1F113

and I want to isolate the ints following the char, what would the sed string be to find numbers after letters?

If I do,
[a-zA-Z]*[0-9], I will get numbers after letters, but I am looking to do something like,

sed 's/[a-zA-Z]*[0-9]/\t[a-zA-Z]*[0-9]/g'

this will give me both the letters and numbers in the new col,

C21    C21 
F231   F231
H42    H42
1C10   C10
1F113  F113

when I want just,

C21    21 
F231   231
H42    42
1C10   10
1F113  113

How do I identify numbers following letters without selecting the letters along with the numbers? I suppose I could do a second run like,

sed 's/\t[a-zA-Z]//g'

but I' not sure that would work either.

LMHmedchem

Hi LMHmedchem,

If you want to do it with sed you could use Regex back reference feature within sed as follow:

echo "C21
F231
H42
1C10
1F113" | sed 's/\(.*[A-Z]\)\([0-9]*\)/\1\2 \2/'
C21 21
F231 231
H42 42
1C10 10
1F113 113

Hope it helps,

Best regards

sed 's_\([0-9][a-zA-Z]\)*\([0-9][0-9]*\)_\1\2\^\2_g' <chars | tr '^' '\t'
C21    21
F231    231
H42    42
1C10    10
1F113    113

If sed doesn't take the \t as a tab then pipe it through tr for character translation (see above)

sed 's/[0-9]*$/& &/' infile
$ echo "C21
F231
H42
1C10
1F113" | sed 's/[0-9]*$/& &/'
C21 21
F231 231
H42 42
1C10 10
1F113 113
$

---------- Post updated at 11:45 PM ---------- Previous update was at 11:41 PM ----------

or

sed 's/[0-9][0-9]*$/& &/' infile
echo "C21
F231
H42
1C10
1F113" |sed -r 's/.*/&\t&/;s/([0-9])?[A-Z]//2'
C21     21
F231    231
H42     42
1C10    10
1F113   113
echo "C21
F231
H42
1C10
1F113" | sed 's/\(.*[a-zA-Z]\)\([0-9]*\)/& \2/g'

21
231
42
10
113

@tene,

You can get the same result with more simple statement

sed 's/.*[^0-9]//' infile

Both these commands are not working.There is no change in output.

Which OS / shell do you run ?

@ctsgnb
I ran in bash.

@tene

Oooops, you true, lol! ... i mixed with the initial statement, :wink:

but what you propose can still be simplified this way:

sed 's/.*[^0-9]//' infile

Yes right, but here we cannot print the original string.
Anyways, I was just trying out the \2 thing in my command..
I am just exploring different ways.

I think the best way to do it is what i proposed in post #4

( the one that cgkmal comments in detail in his post #10)

There must be a dearth of decent sed/awk problems around at the moment; you guys need more complex problems to solve...