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
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.
Thanks in advance
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With