Using sed to replace a number greater than a specified number at a specified position

后端 未结 4 723
失恋的感觉
失恋的感觉 2021-01-25 06:45

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 14         


        
4条回答
  •  别那么骄傲
    2021-01-25 07:21

    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
    

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

    Or using substitution:

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

提交回复
热议问题