問題描述
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}"