awk conditional assignment

Dear all,

I want to use awk to read the three columns in a file called "test" and change them to ( 1.5 1.5 1.5) if any element is found to be greater than three. A part of the file is shown below:

(0.478318 0.391032 -0.14054)
(0.45562 0.392523 -0.121685)
(0.437204 0.392811 -0.106158)
(0.420991 0.391615 -0.0944351)
(0.407585 0.389046 -0.0856931)
(-9.64808 6.512 -11.9177)
(-21.2522 4.2609 -15.8548)
(-36.7927 5.73519 -25.5674)
(-56.1474 14.0543 -43.4295)

I tried the following but it didn't work. Please help.

sed 's/[()]//g' test | awk -F " " '{if($1>2) $1 = $1/$1 + 1.5}' 

Thanks,
Fairus

---------- Post updated at 03:35 AM ---------- Previous update was at 03:27 AM ----------

I should say " (2.5 2.5 2.5) "

With apology,
Fairus

---------- Post updated at 03:38 AM ---------- Previous update was at 03:35 AM ----------

should be "greater than two"

Early morning mistake,

Sorry again,
Fairus

Hi mfmohdyasin,

Try with:

awk -F"[( )]" '{if($2>2 || $3>2 || $4>2) print "(2.5 2.5 2.5)";else print $0}' inputfile
(0.478318 0.391032 -0.14054)
(0.45562 0.392523 -0.121685)
(0.437204 0.392811 -0.106158)
(0.420991 0.391615 -0.0944351)
(0.407585 0.389046 -0.0856931)
(2.5 2.5 2.5)
(2.5 2.5 2.5)
(2.5 2.5 2.5)
(2.5 2.5 2.5)

Regards

cat input.txt | awk 'BEGIN{ 
  while (getline  > 0){
    F1 = $1
    F2 = $2
    F3 = $3
    gsub (/\(/,"",F1)
    gsub (/\(/,"",F3)
    if (F1 > 2 || F2 > 2 || F3 > 2){
      print "(2.5 2.5 2.5)"
    }else{
      print $0
    }
  }
}'

Thanks e/one

Fairus