如何在 IF 条件下应用 2 个 awks?

How to apply 2 awks inside an IF condition?

我有一个格式如下的文件:

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

我想做这个子结构 $2-$3 并在我的文件的开头添加一个额外的列,基于第二列的 -/+ 符号以获得以下格式:

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

我使用了这个命令

awk '{print ,-,,}' FILE |if ( < 0 ) then awk '{print "-",[=12=]}' ; else awk '{print "+",[=12=]}'; fi 

哪个给予:

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

我尝试用大括号 "play" 但似乎我的情况在第一个 awk 后停止了。我的命令做错了什么?

能否请您尝试以下。

awk '{=(>?"+":"-") OFS  OFS -} 1' Input_file

如果您想要 TAB 分隔输出,请尝试以下操作。

awk 'BEGIN{OFS="\t"} {=(>?"+":"-") OFS  OFS -} 1' Input_file

说明:为以上代码添加详细说明。

awk '                                      ##Starting awk program from here.
{
  =(>?"+":"-") OFS  OFS -      ##re-creating 1st field, where firstly checking if 2nd field is greater than 3rd than add + or put - then mentioning value of  and then subtraction of 2nd and 3rd field.
}
1                                          ##1 will print the lines.
' Input_file                               ##Mentioning Input_file name here.