Shell awk不检查Station是否正确显示输出中的所有打印行

Shell awk不检查Station是否正确显示输出中的所有打印行,shell,awk,Shell,Awk,我正在尝试编写以下代码,但awk没有正确检查if语句 #!/bin/bash sqlplus -S username/pwd << EOF SET ECHO off; Set FEEDBACK off; SET TRIMSPOOL on; SET TAB off; SET TERMOUT OFF; set HEADSEP off; SET HEADING on; SET LINESIZE 1000; SET WRAP off; set serveroutput off; SPO

我正在尝试编写以下代码,但awk没有正确检查if语句

#!/bin/bash

sqlplus -S username/pwd << EOF

SET ECHO off;
Set FEEDBACK off;
SET TRIMSPOOL on;
SET TAB off;
SET TERMOUT OFF;
set HEADSEP off;
SET HEADING on;
SET LINESIZE 1000;
SET WRAP off;
set serveroutput off;

SPOOL /tmp/sql_output.xls
select  * from (
select  PROCESS_SRC_STATUS_IND,PROCESS_RUN_TIME_ID,PROCESS_ID from      raptore.tb_process_prod c 
where PROCESS_ID in (116)
order by PROCESS_CREATE_DTM desc
)
where rownum=1

spool off
exit;
EOF

awk '{

if ( $1 == "C")
then
    print "Job J4051 has successfully run for date " $2 

elif ($1 == "P")
then
    print "Job J4051 is pending for date " $2 

elif ($1 == "F")
then
    print "Job J4051 is failed for date " $2

}' /tempt/sql_output.xls
#/bin/bash

sqlplus-S username/pwd在
awk的
if
子句中没有
then

语法应该如下所示

awk '
    {

    if(conditional-expression1)
        action1;
    else if(conditional-expression2)
        action2;
    else if(conditional-expression3)
        action3;
        .
        .
    else
        action n;
    }
   '
awk '{
            if ( $1 == "C")
                print "Job J4051 has successfully run for date " $2 
       else if ( $1 == "P" )
                print "Job J4051 is pending for date " $2 
       else if ( $1 == "F" )
                print "Job J4051 is failed for date " $2
     }
    '  infile
  • 如果条件表达式1为true,则action1将为true 表演
  • 如果conditional-expression1为false,则conditional-expression2为false 将被检查,如果为真,将执行并继续执行操作2 这样地。如果不存在以下情况,则将执行最后一个else部分: 条件表达式为true
修改如下

awk '
    {

    if(conditional-expression1)
        action1;
    else if(conditional-expression2)
        action2;
    else if(conditional-expression3)
        action3;
        .
        .
    else
        action n;
    }
   '
awk '{
            if ( $1 == "C")
                print "Job J4051 has successfully run for date " $2 
       else if ( $1 == "P" )
                print "Job J4051 is pending for date " $2 
       else if ( $1 == "F" )
                print "Job J4051 is failed for date " $2
     }
    '  infile

将提供一个更惯用的
awk
版本

 $ awk '$1=="C"{text="Job J4051 has successfully run for date"} 
        $1=="P"{text=...} 
        ... 
        {print text, $2}' file

您是否尝试打印
$1
?他的价值是什么?也许你不需要使用awk。。您应该使用标准bash
if
statement它使用awk读取sql查询的输出…normal if else无法工作我想我需要将输出值分配给一个变量,因此我使用awkelse if抛出语法错误awk:cmd。行:7:else如果($1==“P”)awk:cmd。第7行:^语法错误awk:cmd。行:11:else如果($1==“F”)awk:cmd。第11行:^语法错误请再次检查