I have a text file which contain only 1 line of text 1314:Battery:1.90:50:30I'm trying to figure out if is there anyway to do a grep and sed to change the value 50 and 30 to the following1314:Battery:1.90:45:35which I would reduce 5 from 50 and increase 5 from 30. Please guide me if there is a better way to solve this problem ? I just started picking up this scripting. Thanks =)
find and replace a value in a line of text
text processing;sed;grep;replace
With perl:perl -i -F: -lape '$F[3]-=5;$F[4]+=5;$_=join :,@F' the-fileWith sh (assuming those numbers are always decimal integers without leading zeros):IFS=: read -r a b c d e < the-file &&  printf '%s\n' $a:$b:$c:$((d-5)):$((e+5)) > the-fileWith recent versions of GNU awk:gawk -i inplace -F: -vOFS=: '{$4-=5;$5+=5}1' the-file