Date: Thu, 13 Jan 2011 06:28:19 +0100 From: Polytropon <freebsd@edvax.de> To: FreeBSD Questions <freebsd-questions@freebsd.org> Subject: awk question: replacing "%d%s" by "%d %s" Message-ID: <20110113062819.4ecb89d9.freebsd@edvax.de>
next in thread | raw e-mail | index | archive | help
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, ...
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20110113062819.4ecb89d9.freebsd>