On Thu, Jan 13, 2011 at 12:28 AM, Polytropon <free...@edvax.de> wrote: > I have strings of the form either "<number(s)>" or > "<number(s)><letter>". I catch them with ...
> 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 This feels like it could be faster, but is reasonable: $ cat data.txt 1 12 3 1d 1dc 12d 12dc 123d 123dc 123dcb $ cat control.txt 1 12 3 1 d 1 dc 12 d 12 dc 123 d 123 dc 123 dcb $ awk < data.txt > experiment.txt '{ num = $1 ; sub(/[^0-9]+$/, "", num) ; lets = $1 ; sub(/^[0-9]+/, "", lets); print num " " lets }' ; diff -cw control.txt experiment.txt $ # The above puts a space at the end of the first 3 lines. If that is bad, try: $ awk < data.txt > experiment.txt '{ num = $1 ; sub(/[^0-9]+$/, "", num) ; lets = $1 ; sub(/^[0-9]+/, "", lets); if (length(lets)) { print num " " lets } else { print num } }' ; diff control.txt experiment.txt $ Tom -- http://EverythingSysadmin.comĀ -- my blog (new posts Mon and Wed) http://www.TomOnTime.com -- my advice (more videos coming soon) _______________________________________________ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"