awk question: replacing "%d%s" by "%d %s"

Polytropon freebsd at edvax.de
Thu Jan 13 05:28:22 UTC 2011


I'm aware that this is not an awk question list, but I'm
confident there are many awk gurus here who can surely
help me with such a stupid problem. I also know that I
get more and more stupid myself for NOT being able to
solve this, even after... some nearly infinite time. :-)

I have strings of the form either "<number(s)>" or
"<number(s)><letter>". I catch them with

	if(match(nr, "[a-z]"))
		...

where "nr" is the name of the string. What I need
is a simple space between <number(s)> and <letter>,
so for example "12a" would get "12 a", "6d" would
get "6 d", and "58" would stay unchanged. I've tried
with split(), with array manipulation and could
produce 10 lines of code that didn't work as intended
(it produced "1122aa", "66dd" and "5588" according
to the examples above).

Obviously, sub(nr, "[a-z]", " [a-z]"); is nonsense.

Can anybody please tell me the obvious and easy way
which I am missing? Thanks a lot! =^_^=

The reason I'd like to do this in awk is that I've
already spent enough time creating a format converter
in awk that works very fine, as intended, but is missing
just this little feature.


-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...


More information about the freebsd-questions mailing list