awk 如果有多個條件拋出錯誤 (awk if with multiple condition throws error)


問題描述

awk 如果有多個條件拋出錯誤 (awk if with multiple condition throws error)

Simple Awk with multiple conditions inside if with binary operator. Its is spitting out error. See the below 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.

A snipped of few lines from input data is as follows...

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:

Assuming you are on Windows, change your command line:

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}"

(by senrameshcaptcha)

參考文件

  1. awk if with multiple condition throws error (CC BY‑SA 3.0/4.0)

#conditional-statements #if-statement #awk






相關問題

在 SSRS 中使用條件來提高可見性 (using conditionals in SSRS for visibility)

Smarty - {IF} {/IF} 內的條件太多 (Smarty - Too many conditions inside {IF} {/IF})

awk 如果有多個條件拋出錯誤 (awk if with multiple condition throws error)

正則表達式錯誤,嵌套標籤 (Regex error, nested tags)

警告:分配條件 (Warning: Assignment in condition)

JavaScript 中的條件語句 (Conditional Statement in JavaScript)

與 linus 條件 '-z' '-n' 混淆 (Confuse with the linus conditions '-z' '-n')

如果條件為真,則將表達式添加到循環中 (if condition is true, add an expression to a loop)

為什麼用多態性替換條件有用? (Why is replacing conditionals with polymorphism useful?)

如何使用條件將一個數據框列的值與另一個數據框列的值匹配? (How do you match the value of one dataframe's column with another dataframe's column using conditionals?)

使用另一個數據框的條件創建一個新列 (Create a new column with a condition of another dataframe)

排除具有空值的 Python 列表 (Excluding Python Lists With Empty Values)







留言討論