Awk/Bash将数字从行首移动到行尾 [英] Awk/Bash move digits from front of line to end of line

查看:85
本文介绍了Awk/Bash将数字从行首移动到行尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将数字/数字字符串从行首移动到行尾,输入示例:

I want to move the digits/numeric string from front of line to end of line, example of input:

123example
321example
34292example

预期输出:

example123
example321
example34292

推荐答案

GNU awk的match函数可以完成这项工作:

GNU awk's match function can do the job:

gawk 'match($0, /^([0-9]+)(.*)$/, m) {print m[2] m[1]}' yourfile.txt

但是,老实说,我会使用sed来完成此任务(如@anubhava建议的那样).

but, honestly, I would use sed for this task (as @anubhava suggested).

这篇关于Awk/Bash将数字从行首移动到行尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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