Hi,
I am running into a small issue here trying to load a file to a DB.
Basically I am trying to get the numbers that are in a string with alot of garbage.
So I tried it with a simple awk hack but it fails. I can´t figure out what I am doing wrong but here is a sample using an echo so keep it short:
echo "$%$&&$··....aaaffff><SPP0022555445DFDDSDFvdbdbd" |awk ' { /[0-9]+/ ; print }'
I expected "0022555445" to print but instead I get:
$%$&&?·....aaaffff><SPP0022555445DFDDSDFvdbdbd
now, I thought, wait, I am not selecting correctly. So I did a simple test replace my selection with something, like this:
echo "$%$&&$··....aaaffff><SPP0022555445DFDDSDFvdbdbd" |awk ' { sub(/[0-9]+/, "<AAAAA>"); print }'
Here is what I get
$%$&&?·....aaaffff><SPP<AAAAA>DFDDSDFvdbdbd
As you can see I am selecting all the digits and replacing them with a "<AAAAA>" correctly.
I am a little rusty in figuring this one out. Again, all I want it the print all the numbers in the range [0-9] from a string.
Thank you all in advanced for helping out.
Regards,
Jose
I am running into a small issue here trying to load a file to a DB.
Basically I am trying to get the numbers that are in a string with alot of garbage.
So I tried it with a simple awk hack but it fails. I can´t figure out what I am doing wrong but here is a sample using an echo so keep it short:
echo "$%$&&$··....aaaffff><SPP0022555445DFDDSDFvdbdbd" |awk ' { /[0-9]+/ ; print }'
I expected "0022555445" to print but instead I get:
$%$&&?·....aaaffff><SPP0022555445DFDDSDFvdbdbd
now, I thought, wait, I am not selecting correctly. So I did a simple test replace my selection with something, like this:
echo "$%$&&$··....aaaffff><SPP0022555445DFDDSDFvdbdbd" |awk ' { sub(/[0-9]+/, "<AAAAA>"); print }'
Here is what I get
$%$&&?·....aaaffff><SPP<AAAAA>DFDDSDFvdbdbd
As you can see I am selecting all the digits and replacing them with a "<AAAAA>" correctly.
I am a little rusty in figuring this one out. Again, all I want it the print all the numbers in the range [0-9] from a string.
Thank you all in advanced for helping out.
Regards,
Jose