使用sed在指定位置替换大于指定数字的数字 [英] Using sed to replace a number greater than a specified number at a specified position

查看:67
本文介绍了使用sed在指定位置替换大于指定数字的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个脚本来替换所有大于以下位置的指定数字的数字.

I need to write a script to replace all the numbers greater than an specified number which is in following position.

1499011200 310961583 142550756 313415036 146983209

如果第二项的值超过 300000000,我在这里编写脚本.我需要将整行替换为我想要的值,如

Here I am writing a script if the second term exceeds in value greater than 300000000. I need the whole line to be replaced by my desired value like

1499011200 250000000 XXXX XXXX XXXX

我希望我已经把我的问题说清楚了.

I hope I have made my question clear.

提前致谢

推荐答案

这可能对你有用(GNU sed):

This might work for you (GNU sed):

sed -r '/^\S+\s+(300000000|[1-2][0-9]{8}|[0-9]{1,8})\s/!c change' file

如果是 300000000 或更少就保留它,否则改变它.

If it's 300000000 or less keep it, otherwise change it.

或者使用替换:

sed '/^\S\+\s\+\(300000000\|[1-2][0-9]\{8\}\|[0-9]\{1,8\}\)\s/!s/^\(\S\+\s\+\).*/\1250000000 XXXX XXXX XXXX/' file

这篇关于使用sed在指定位置替换大于指定数字的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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