AWK将字符串拆分为单词和数字 [英] Awk split string into words and numbers

查看:61
本文介绍了AWK将字符串拆分为单词和数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试拆分字母和数字的边界,但是具有环顾四周的解决方案失败:

I am trying to split of letter and number boundaries, but the solution with lookarounds fails:

echo 50cats30dogs100squirrels | awk '{split($0,a,/(?<=\D)(.*)(?=\d)/); print a[1],a[2],a[3]}'

awk: illegal primary in regular expression (?<=\D)(.*)(?=\d) at <=\D)(.*)(?=\d)
 source line number 1
 context is
     >>> {split($0,a,/(?<=\D)(.*)(?=\d)/) <<<

在Awk中还有其他方法吗?

Is there a way to do this in Awk in other way?

很抱歉,不清楚.预期的输出是仅添加这样的空格:

Sorry for not being clear. The expected output is to just add spaces like this:

50 cats 30 dogs 100 squirrels

推荐答案

仅适用于您显示的示例.如果这是您要寻找的,请您尝试尝试.用GNU awk 编写和测试(我相信应该可以在任何 awk 中使用).

With your shown samples only. Could you please try following, if this is what you are looking for. Written and tested in GNU awk(should work in any awk I believe).

echo "50cats30dogs100squirrels" | awk '{gsub(/[^0-9]+/," & ")} 1'

显示的示例的输出如下:

Output will be as follows for shown samples:

50 cats 30 dogs 100 squirrels

这篇关于AWK将字符串拆分为单词和数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆