awk如果有多个条件抛出错误

时间:2013-07-23 11:45:20

标签: if-statement awk conditional-statements

如果使用二元运算符,内部有多个条件的简单Awk。它正在吐出错误。 见下面的O / P.

D:\Program Files\Veritas\NetBackup\bin>bpdbjobs -report -most_columns | awk '{FS=","; if ($2 == 0 || $11 > 0) printf "%s,%s,%s,%d,%s,%s,%s,%d:%d:%d,%d,%d\n", $7,$5,$6,$4,$8,strftime("%c",$9),strftime("%c", $11),$10/(60*60),$10%(60*60)/60,$10%60,$16,$15}' > c:\bpdbjobs_report_processed.csv
awk: cmd. line:2: {FS=","; if ($2 == 0
awk: cmd. line:2:                      ^ unexpected newline or end of string
'$11' is not recognized as an internal or external command,
operable program or batch file.

从输入数据中删除几行如下......

23123,0,0,,xxxxxEX-IS,Daily-Differen-Noon,xxxxxex, ,1374573600,0000007052,0000000000, ,1,,,,,0,,root,1,16,1,9999,root,xxx-abc-nbkp,2,2,0,0,0,0,0,23123,,,,,,,,,,,,,0,0,0,0,0,,0,,,,Drives are in use in storage unit (xxx-abc-nbkp-hcart-robot-tld-0),
23122,17,3,0,,,,,1374566996,0000000035,1374567031,,1,,,,,100,7644,root,,,,,,xxx-abc-nbkp,,,,,,0,0,,,,,,,,,,,,,,,,,,,,,,,, ,
23121,2,4,0,,,xxx-abc-BANCS1,xxx-abc-nbkp,1374557721,0000022931,0000000000,,1,,,,/backups/rpru/scripts/check_crs_listener.out,0,9628,root,,,,90000,root,xxx-abc-nbkp,,,,0,10,0,0,,,,,,,,,,xxx-abc-nbkp,,,,1,1,,,,,1,,,, ,
23120,0,1,,xxxxxEX-MB-BF,Daily,xxxxxex,xxx-abc-nbkp,1374555781,0000024871,0000000000,xxx-abc-nbkp-hcart-robot-tld-0,1,3,8579904,38000,/Microsoft Exchange Mailboxes/Nisha Jayadas [njayadas]/Top of Information Store/Inbox/FW: xxxxx Final Report for 30 Jun 2013\, 01 Jul 2013 and 02 Jul 2013 ,61,,root,0,16,4,0,other,xxx-abc-nbkp,3,3,0,0,55506,0,0,23120,346,,,,,,,,,,,0,0,0,0,0,0,xxxxxex_1374555781,1,,,0, ,

1 个答案:

答案 0 :(得分:2)

假设您使用的是Windows,请更改命令行:

awk -F, "{if ($2 == 0 || $11 > 0) printf \"%s,%s,%s,%d,%s,%s,%s,%d:%d:%d,%d,%d\n\", $7,$5,$6,$4,$8,strftime(\"%c\",$9),strftime(\"%c\", $11),$10/(60*60),$10%(60*60)/60,$10%60,$16,$15}"