jeudi 30 avril 2020

How to apply 2 awks inside an IF condition?

I have a file with the following format:

name   3  4
name  -4  3
name  -5  4
name   2 -4 

I want to make this substruction $2-$3 and to add an extra column at the beginning of my file with the -/+ sign based on the second column to obtain the following format:

   - name  -1  3  4
   - name  -7 -4  3
   - name  -9 -5  4
   + name   6  2 -4 

I used this command

awk '{print $1,$2-$3,$2,$3}' FILE |if ($2 < 0 ) then awk '{print "-",$0}' ; else awk '{print "+",$0}'; fi 

Which giving:

   - name  -1  3  4
   - name  -7 -4  3
   - name  -9 -5  4
   - name   6  2 -4 

I tried to "play" with curly brackets but it seems my condition stops after the first awk. What did I make wrong on my command?

Aucun commentaire:

Enregistrer un commentaire