我想在awk中得到更好,並使用它的一些CSV格式的文件,它有多個標題行與n
行後實際報告開始。該報告還有一個需要丟棄的頁腳。以下是我想結合條件生成一個乾淨的報告awk打印行與n列,並忽略最後一行
awk -F, '{NF==25} END {NR>2 {print l} {l=$0}}' 6999_RACV_Master_Conversion_Report_csv_20171005_114903_618978908.csv > 6999_RACV_Master_Conversion_Report_csv_20171005_114903_618978908_formatted.csv
與上述我能夠擺脫頁腳,但標題存在。這裏是興田樣本數據
Date/Time Generated,10/5/17 11:46 AM
Report Time Zone,Australia/Sydney
Account ID,6999
Date Range,9/1/17 - 9/30/17
Floodlight Configuration,Equals:6017727
Activity,Equals:RACV_INT_MMO_Consideration (4136140)
Activity,Equals:RACV_INT_MMO_Sales (4135439)
Activity,Equals:RACV_PARTNER_TMNFATravel_Consideration (4136141)
Activity,Equals:RACV_PARTNER_TMNFATravel_Sales (4136142)
Campaign,Equals:RACV - C&E Display FY17 - NEW - 16.11.17 (10581787)
Campaign,Equals:RACV - Commercial Insurance Display FY17 (11180171)
Campaign,Equals:RACV - EHA Display FY17 - NEW - 16.11.16 (10559465)
Campaign,Equals:RACV - EHA Online Video FY17 - NEW - 16.11.16 (10604948)
Campaign,Equals:RACV - EHA The Block 2017 - Digital (20185347)
Campaign,Equals:RACV - ERA Display FY17 - NEW - 16.11.16 (10548416)
Campaign,Equals:RACV - ERA Online Video FY17 - NEW - 16.11.16 (10554300)
Campaign,Equals:RACV - Business Loans Digital FY17 - NEW - 16.11.16 (10647172)
Campaign,Equals:RACV - Finance Caravan Loans Display FY17 - NEW - 16.11.16 (10580422)
Campaign,Equals:RACV - Finance Display FY17 - NEW - 16.11.16 (10598350)
Campaign,Equals:RACV - Home Security Social FY17 - NEW - 16.11.16 (10701389)
Campaign,Equals:RACV - Mobile Tyres FY18 - NEW 01.07.17 (20089973)
Campaign,Equals:RACV - Energy Comapre FY18 (Child) (20214029)
Campaign,Equals:RACV Home Products & Services (20321908)
Campaign,Equals:RACV - Personal Insurance Display FY17 - NEW - 16.11.16 (10605443)
Campaign,Equals:RACV - Personal Insurance Online Video FY17 - NEW - 16.11.16 (10730454)
Campaign,Equals:RACV - Renters Insurance FY1718 (20192006)
Campaign,Equals:RACV - Resorts Display FY17 - NEW - 16.11.16 (10512704)
Campaign,Equals:RACV - Resorts Online Video FY17 - NEW - 16.11.16 (10591278)
Campaign,Equals:RACV - Travel Insurance FY17 Display - NEW - 16.11.16 (10613550)
MRC Accredited Metrics,None
Report Fields
Date,Activity,Activity ID,Campaign,Campaign ID,Site (DCM),Placement,Creative,Impression Count,IsPartnerName (string),OrderType (string),OrderProd (string),OrderName (string),OrderID (string),OrderRevenue (string),OrderPAX (string),OrderQ
uantity (string),OrderStep (string),OrderDateFrom (string),OrderDateTill (string),Conversion URL,Click-through Conversions,View-through Conversions,Total Conversions,Total Revenue
2017-09-01,RACV_INT_MMO_Consideration,4136140,RACV - Business Loans Digital FY17 - NEW - 16.11.16,10647172,Accuen Australia,Business Loans_OMDP_DBM_Custom Affinity_Leaderboard_728x90_Desktop_P25-54_Performance_,RAC18580-Car-Loans-Digital
-banners-728-x-90,12,,,,Car-Insurance-quote-Step-1,,,,,Step-1,,,;src=6017727;type=racv-0;cat=racv_000;u7=;u8=;u9=;u10=;u11=;u12=;u13=Car-Insurance-quote-Step-1;u16=;u17=;u18=Step-1;u20=;u21=;dc_lat=;dc_rdid=;tag_for_child_directed_treatm
ent=;ord=1256092675587.8044;~oref=https://mymembership.racv.com.au/wps/portal/mqte/!ut/p/b1/hY3JDoJAEES_iHQPmAGOIATDKg4izIXgEgRZggskfL3oHa1bJa9eAYeUSBSpLBMKCfA2H8oif5Zdm9efzmkmIlWZYxFUQrZGTY-IE7AAUSQzkM4ALkTDf3sbeFF3x_nqAPwL_3D5m665QDpj8
qLTkyCCBFcZq5SudwfdnUwprsbxMTHVrkLlNZ2I7zq9Z-DVi9Rke453e13T7oLhmtDwWrkJVvEG7M0tJA!!/dl4/d5/L2dBISEvZ0FBIS9nQSEh/pw/Z7_2069SKG108QSC0ABT1KOSO00M3/act/id=0/p=backJspName=QFBuote_About_You/p=javax.portlet.action=backActionSubmit/36551187388
3/-/,0.00,1.00,1,0.000000000
2017-09-01,RACV_INT_MMO_Consideration,4136140,RACV - Business Loans Digital FY17 - NEW - 16.11.16,10647172,Accuen Australia,Business Loans_OMDP_DBM_Custom Affinity_Leaderboard_728x90_Desktop_P25-54_Performance_,RAC18580-Car-Loans-Digital
-banners-728-x-90,12,,,,Car-Insurance-quote-Step-1,,,,,Step-1,,,;src=6017727;type=racv-0;cat=racv_000;u7=;u8=;u9=;u10=;u11=;u12=;u13=Car-Insurance-quote-Step-1;u16=;u17=;u18=Step-1;u20=;u21=;dc_lat=;dc_rdid=;tag_for_child_directed_treatm
ent=;ord=1936578182591.1943;~oref=https://mymembership.racv.com.au/wps/portal/mqte,0.00,1.00,1,0.000000000
2017-09-01,RACV_INT_MMO_Consideration,4136140,RACV - Business Loans Digital FY17 - NEW - 16.11.16,10647172,Accuen Australia,Business Loans_OMDP_DBM_Custom Affinity_Leaderboard_728x90_Desktop_P25-54_Performance_,RAC18580-Car-Loans-Digital
-banners-728-x-90,12,,,,Car-Insurance-quote-Step-1,,,,,Step-1,,,;src=6017727;type=racv-0;cat=racv_000;u7=;u8=;u9=;u10=;u11=;u12=;u13=Car-Insurance-quote-Step-1;u16=;u17=;u18=Step-1;u20=;u21=;dc_lat=;dc_rdid=;tag_for_child_directed_treatm
ent=;ord=5398916632833.284;~oref=https://mymembership.racv.com.au/wps/portal/mqte/!ut/p/b1/hY3JDoJAEES_iHQPmAGOIATDKg4izIXgEgRZggskfL3oHa1bJa9eAYeUSBSpLBMKCfA2H8oif5Zdm9efzmkmIlWZYxFUQrZGTY-IE7AAUSQzkM4ALkTDf3sbeFF3x_nqAPwL_3D5m665QDpj8q
LTkyCCBFcZq5SudwfdnUwprsbxMTHVrkLlNZ2I7zq9Z-DVi9Rke453e13T7oLhmtDwWrkJVvEG7M0tJA!!/dl4/d5/L2dBISEvZ0FBIS9nQSEh/pw/Z7_2069SKG108QSC0ABT1KOSO00M3/act/id=0/p=backJspName=QFBuote_About_You/p=javax.portlet.action=backActionSubmit/365511963564
/-/,0.00,1.00,1,0.000000000
Grand Total:,---,---,---,---,---,---,---,---,---,---,---,---,---,---,---,---,---,---,---,---,810.00,39373.00,40183,0.000000000
預期輸出: -
Date,Activity,Activity ID,Campaign,Campaign ID,Site (DCM),Placement,Creative,Impression Count,IsPartnerName (string),OrderType (string),OrderProd (string),OrderName (string),OrderID (string),OrderRevenue (string),OrderPAX (string),OrderQ
uantity (string),OrderStep (string),OrderDateFrom (string),OrderDateTill (string),Conversion URL,Click-through Conversions,View-through Conversions,Total Conversions,Total Revenue
2017-09-01,RACV_INT_MMO_Consideration,4136140,RACV - Business Loans Digital FY17 - NEW - 16.11.16,10647172,Accuen Australia,Business Loans_OMDP_DBM_Custom Affinity_Leaderboard_728x90_Desktop_P25-54_Performance_,RAC18580-Car-Loans-Digital
-banners-728-x-90,12,,,,Car-Insurance-quote-Step-1,,,,,Step-1,,,;src=6017727;type=racv-0;cat=racv_000;u7=;u8=;u9=;u10=;u11=;u12=;u13=Car-Insurance-quote-Step-1;u16=;u17=;u18=Step-1;u20=;u21=;dc_lat=;dc_rdid=;tag_for_child_directed_treatm
ent=;ord=1256092675587.8044;~oref=https://mymembership.racv.com.au/wps/portal/mqte/!ut/p/b1/hY3JDoJAEES_iHQPmAGOIATDKg4izIXgEgRZggskfL3oHa1bJa9eAYeUSBSpLBMKCfA2H8oif5Zdm9efzmkmIlWZYxFUQrZGTY-IE7AAUSQzkM4ALkTDf3sbeFF3x_nqAPwL_3D5m665QDpj8
qLTkyCCBFcZq5SudwfdnUwprsbxMTHVrkLlNZ2I7zq9Z-DVi9Rke453e13T7oLhmtDwWrkJVvEG7M0tJA!!/dl4/d5/L2dBISEvZ0FBIS9nQSEh/pw/Z7_2069SKG108QSC0ABT1KOSO00M3/act/id=0/p=backJspName=QFBuote_About_You/p=javax.portlet.action=backActionSubmit/36551187388
3/-/,0.00,1.00,1,0.000000000
2017-09-01,RACV_INT_MMO_Consideration,4136140,RACV - Business Loans Digital FY17 - NEW - 16.11.16,10647172,Accuen Australia,Business Loans_OMDP_DBM_Custom Affinity_Leaderboard_728x90_Desktop_P25-54_Performance_,RAC18580-Car-Loans-Digital
-banners-728-x-90,12,,,,Car-Insurance-quote-Step-1,,,,,Step-1,,,;src=6017727;type=racv-0;cat=racv_000;u7=;u8=;u9=;u10=;u11=;u12=;u13=Car-Insurance-quote-Step-1;u16=;u17=;u18=Step-1;u20=;u21=;dc_lat=;dc_rdid=;tag_for_child_directed_treatm
ent=;ord=1936578182591.1943;~oref=https://mymembership.racv.com.au/wps/portal/mqte,0.00,1.00,1,0.000000000
2017-09-01,RACV_INT_MMO_Consideration,4136140,RACV - Business Loans Digital FY17 - NEW - 16.11.16,10647172,Accuen Australia,Business Loans_OMDP_DBM_Custom Affinity_Leaderboard_728x90_Desktop_P25-54_Performance_,RAC18580-Car-Loans-Digital
-banners-728-x-90,12,,,,Car-Insurance-quote-Step-1,,,,,Step-1,,,;src=6017727;type=racv-0;cat=racv_000;u7=;u8=;u9=;u10=;u11=;u12=;u13=Car-Insurance-quote-Step-1;u16=;u17=;u18=Step-1;u20=;u21=;dc_lat=;dc_rdid=;tag_for_child_directed_treatm
ent=;ord=5398916632833.284;~oref=https://mymembership.racv.com.au/wps/portal/mqte/!ut/p/b1/hY3JDoJAEES_iHQPmAGOIATDKg4izIXgEgRZggskfL3oHa1bJa9eAYeUSBSpLBMKCfA2H8oif5Zdm9efzmkmIlWZYxFUQrZGTY-IE7AAUSQzkM4ALkTDf3sbeFF3x_nqAPwL_3D5m665QDpj8q
LTkyCCBFcZq5SudwfdnUwprsbxMTHVrkLlNZ2I7zq9Z-DVi9Rke453e13T7oLhmtDwWrkJVvEG7M0tJA!!/dl4/d5/L2dBISEvZ0FBIS9nQSEh/pw/Z7_2069SKG108QSC0ABT1KOSO00M3/act/id=0/p=backJspName=QFBuote_About_You/p=javax.portlet.action=backActionSubmit/365511963564
/-/,0.00,1.00,1,0.000000000
請表明樣品輸入和預期輸出 –
除了Akshay要求發佈樣本數據(您應該將代碼標籤放入您的文章中)之外,我注意到END塊中的條件NR> 2對於所有行都無法正常工作,因爲END一旦完成讀取Input_file的所有行,就會出現awk部分。 – RavinderSingh13
感謝您添加示例輸入,期望的輸出是什麼,請在代碼標記中添加 – RavinderSingh13