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

后端 未结 4 718
失恋的感觉
失恋的感觉 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:32

    In awk:

    $ awk '$2>300000000{for(i=3;i<=NF;i++)$i="XXXX"}1' file
    1499011200 310961583 XXXX XXXX XXXX
    

    Explained:

    $ awk '                 # using awk
    $2>300000000 {          # if the second value is greater than ...
        for(i=3;i<=NF;i++)  # for each value aftef the second
            $i="XXXX"       # replace it with XXXX
    }1' file                # output
    

提交回复
热议问题