awk处理关联文件问题
tabclums.txt 内容如下:
tp_monitor_val_manager|start_date|
tp_monitor_val_manager|end_date|
settle_catalog_array_temporary|start_date|
tp_hcode_bak|start_date|
tp_hcode_bak|end_date|
table_operation_log|deal_datetime|
flux_monitor_instance|sampling_date|
tp_discount_temporary|discount_date|
tp_discount_temporary|start_time|
tp_discount_temporary|end_time|
tp_discount_temporary|start_date|
tp_discount_temporary|end_date|
tp_discount|discount_date|
tp_discount|start_time|
tp_discount|end_time|
tp_discount|start_date|
tp_discount|end_date|
tp_dz_hcode|start_datetime|
tp_dz_hcode|end_datetime|
tp_card_rate_part|start_date|
tp_card_rate_part|end_date|
tp_iden_office|start_date|
tp_iden_office|end_date|
tp_iden_call_happen_area|start_date|
tp_iden_call_happen_area|end_date|
tp_icp_rule|start_datetime|
tp_icp_rule|end_datetime|
tp_iden_settle_logic|adjust_time|
tp_iden_office_temporary|start_date|
tp_iden_office_temporary|end_date|
tp_hcode_temporary|start_date|
tp_hcode_temporary|end_date|
tp_hcode|start_date|
tp_hcode|end_date|
tp_gaoe_def|start_datetime|
tp_gaoe_def|end_datetime|
tpz_iden_settle_type|start_datetime|
tpz_iden_settle_type|end_datetime|
tpz_rate_cell|start_datetime|
tpz_rate_cell|end_datetime|
tp_163_config|validate_rule1|
tp_163_config|validate_rule2|
tp_special_phone_temporary|start_date|
tp_special_phone_temporary|end_date|
tp_special_phone|start_date|
tp_special_phone|end_date|
tp_toll_ratio_temporary|start_date|
tp_toll_ratio_temporary|end_date|
tp_toll_ratio|start_date|
tp_toll_ratio|end_date|
work_log|log_time|
web_report|create_date|
tp_trunk_temporary|start_date|
tp_trunk_temporary|end_date|
tp_trunk|start_date|
tp_trunk|end_date|
tp_settle_fee_gjj|start_date|
tp_settle_fee_gjj|end_date|
tp_one_year|one_date|
tp_phone_brand|start_date|
tp_phone_brand|end_date|
tp_phone_brand_temporary|start_date|
tp_phone_brand_temporary|end_date|
tp_local_ratio|start_date|
tp_local_ratio|end_date|
tp_inter_tsp_gaoe|start_datetime|
tp_inter_tsp_gaoe|end_datetime|
tp_local_ratio_temporary|start_date|
tp_local_ratio_temporary|end_date|
tp_national_800|valid_time|
tp_national_800|elapse_time|
tp_settle_cycle|start_date|
tp_settle_cycle|end_date|
tp_roam_msc|start_date|
tp_roam_msc|end_date|
product_def|eff_date|
product_def|exp_date|
product_offer|eff_date|
product_offer|exp_date|
flux_monitor_task|stat_last_date|
flux_monitor_task|update_frequency|
flux_monitor_task|update_last_date|
flux_monitor_task|update_deal_flag|
flux_monitor_task|update_product_id|
flux_monitor_task|start_date|
flux_monitor_task|end_date|
life_cycle|eff_date|
life_cycle|exp_date|
alarm|alarm_time|
alarm|process_time|
td_a_month|start_date|
td_a_month|end_date|
tg_task|stat_datetime|
tg_task|stat_last_date|
tg_task|start_date|
tg_task|end_date|
tpj_iden_rate|start_datetime|
tpj_iden_rate|end_datetime|
tpi_iden_settle_type|start_datetime|
tpi_iden_settle_type|end_datetime|
tpi_rate_cell|start_datetime|
tpi_rate_cell|end_datetime|
td_placard|log_time|
s_country_imsi|start_date|
s_country_imsi|end_date|
vpi_settle_type|start_datetime|
vpi_settle_type|end_datetime|
vp_trunk_in|start_date|
vp_trunk_in|end_date|
vp_trunk_out|start_date|
vp_trunk_out|end_date|
operator|valid_date|
operator|psw_mod_date|
tp_ctry|eff_date|
tp_ctry|exp_date|
tp_ctry|update_time|
tp_stt_object|eff_date|
tp_stt_object|exp_date|
tp_stt_object|update_time|
tp_iden_office_temporary_bak|start_date|
tp_iden_office_temporary_bak|end_date|
tp_mss_report_import|sett_date|
tp_settle_rule|start_date|
tp_settle_rule|end_date|
tp_settle_rule_temporary|start_date|
tp_settle_rule_temporary|end_date|
settle_catalog_array_temp|deal_date|
tp_hcode_static_bak|start_date|
tp_hcode_static_bak|end_date|
tabnum.txt内容如下:
alarm|0
flux_monitor_instance|110
flux_monitor_task|2
life_cycle|0
operator|3
product_def|118
product_offer|0
s_country_imsi|0
settle_catalog_array_temp|0
settle_catalog_array_temporary|56264
table_operation_log|1930985
td_a_month|121
td_placard|0
tg_task|15
tp_163_config|0
tp_card_rate_part|0
tp_ctry|249
tp_discount|91
tp_discount_temporary|91
tp_dz_hcode|0
tp_gaoe_def|338
tp_hcode|197690
tp_hcode_bak|174781
tp_hcode_static_bak|193013
tp_hcode_temporary|193013
tp_icp_rule|0
tp_iden_call_happen_area|0
tp_iden_office|53277
tp_iden_office_temporary|53277
tp_iden_office_temporary_bak|53162
tp_iden_settle_logic|9
tp_inter_tsp_gaoe|0
tp_local_ratio|40
tp_local_ratio_temporary|40
tp_monitor_val_manager|0
tp_mss_report_import|176
tp_national_800|16
tp_one_year|365
tp_phone_brand|280
tp_phone_brand_temporary|280
tp_roam_msc|0
tp_settle_cycle|336
tp_settle_fee_gjj|1545
tp_settle_rule|128
tp_settle_rule_temporary|128
tp_special_phone|247
tp_special_phone_temporary|247
tp_stt_object|585
tp_toll_ratio|34
tp_toll_ratio_temporary|34
tp_trunk|1010
tp_trunk_temporary|1010
tpi_iden_settle_type|26
tpi_rate_cell|3
tpj_iden_rate|8464
tpz_iden_settle_type|0
tpz_rate_cell|0
vp_trunk_in|887
vp_trunk_out|897
vpi_settle_type|26
web_report|552
work_log|2912
我想实现tabnum.txt第二个字段不为0时,输出tabclums.txt中的$1,$2的值。怎么用awk实现?
我写了如下语句关联不出来
awk -F\| 'NR==FNR {a[$1]+=$2} NR>FNR&&a[$1]>0 {print $1,$2}' tabnum.txt abclums.txt
请高手解答:顺便请给我讲讲awk的关联方法
[解决办法]
cat data.dat | awk -F"|" '{if($2 != 0) print $1, $2}'
[解决办法]
个人感觉这样最直观
$paste -d"|" tabnum.txt abcclums.txt | awk -F"|" '{if ($2 != 0) print $3, $4}'
还有很多办法的
[解决办法]
只用awk的话可以这样
awk -F"|" '{tmp=$2; getline <abcclums.txt;if (tmp == "0") print $1,$2}' tabnum.txt
[解决办法]
哦,不好意思,是搞错了,弄成了0时输出.改变如下:
- Perl code
[Hsxzhe--16:58:36 awk]$:cat awk.file1BEGIN{ FS="|"}(FILENAME==ARGV[1]){arry1[NR]=$1;arry2[NR]=$2}(FILENAME==ARGV[2] && $2!=0){print arry1[FNR],arry2[FNR]}[Hsxzhe--16:58:44 awk]$:awk -f awk.file1 tabclums.txt tabnum.txttp_monitor_val_manager end_datesettle_catalog_array_temporary start_datetp_hcode_bak end_datetable_operation_log deal_datetimetp_discount_temporary end_timetp_discount_temporary start_datetp_discount_temporary end_datetp_discount start_timetp_discount end_datetp_dz_hcode start_datetimetp_dz_hcode end_datetimetp_card_rate_part end_datetp_iden_office start_datetp_iden_office end_datetp_iden_call_happen_area start_datetp_iden_call_happen_area end_datetp_iden_settle_logic adjust_timetp_iden_office_temporary start_datetp_iden_office_temporary end_datetp_hcode_temporary start_datetp_hcode start_datetp_hcode end_datetp_gaoe_def end_datetimetpz_iden_settle_type start_datetimetpz_iden_settle_type end_datetimetpz_rate_cell start_datetimetpz_rate_cell end_datetimetp_163_config validate_rule2tp_special_phone_temporary start_datetp_special_phone_temporary end_datetp_special_phone start_datetp_special_phone end_datetp_toll_ratio_temporary start_datetp_toll_ratio_temporary end_datetp_toll_ratio start_datetp_toll_ratio end_datework_log log_timeweb_report create_datetp_trunk_temporary start_datetp_trunk_temporary end_datetp_trunk start_datetp_settle_fee_gjj end_datetp_one_year one_datetp_phone_brand start_datetp_phone_brand end_datetp_phone_brand_temporary start_date[Hsxzhe--16:58:52 awk]$: