BooBz wrote: > I have a file : > fghfgh 45 45 100 > hjuhju 90 45 90 > and i want to test the field to rewrite or not another field : > if field2 = 45 and field3 = 45 then field4 = field4 - 10 > if field2 = 45 and field3 = 90 then field4 = field4 - 5 > if field2 = 90 and field3 = 45 then field4 = field4 - 5 > > I don't know if it's possible in bash ? Maybe some language are useful for > the things i want to do ...
Some languages are better suited to this type of manipulation than others. But you are asking in bug-bash and so you must be expecting a bash scripting answer. :-) Try something like this: while read field1 field2 field3 field4; do if [[ $field2 = 45 && $field3 = 45 ]]; then field4=$(($field4 - 10)); fi if [[ $field2 = 45 && $field3 = 90 ]]; then field4=$(($field4 - 5)); fi if [[ $field2 = 90 && $field3 = 45 ]]; then field4=$(($field4 - 5)); fi echo $field1 $field2 $field3 $field4 done There are endless variations but this matched your description fairly closely. Bob