sh SAMPLE.AWK.CODES
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh SAMPLE.AWK.CODES相关的知识,希望对你有一定的参考价值。
#!/usr/bin/gawk -f
# NOTE: string 1st char at pos. 1.
# Functions.
function process_rec4(rec4, tbl_filter){
srch_fltr = substr(rec4, 2, 11) # PoD.
if (srch_fltr in tbl_filter)
{
rec4_orig = tbl_filter[srch_fltr]
if ( (substr(rec4_orig, 591, 10) != substr(rec4, 591, 10)) || (substr(rec4_orig, 752, 2) != substr(rec4, 752, 2)) )
{
print rec4_orig >> FILE_OT
print rec4 >> FILE_OT
line_cnt_ot += 2
}
}
else
{
print "*** ERROR: PoD = " srch_fltr " not in original file!" >> JOB_OUT
exit 99
}
}
# Before first line.
BEGIN {
print "" >> JOB_OUT
print "GAwk Started" >> JOB_OUT
# Constants.
NUM_RECS_INVC = 4
# Variables Init.
line_crnt = ""
load_fltr = ""
srch_fltr = ""
#
line_cnt_in = 0
line_cnt_ot = 0
line_cnt_fltr = 0
#
modulo = 69
#
rec1 = ""
rec2 = ""
rec3 = ""
rec4 = ""
rec4_orig = ""
}
# 1st File (filter).
# Load filter to table.
FNR==NR {
line_cnt_fltr += 1
line_crnt = $0
modulo = line_cnt_fltr % NUM_RECS_INVC
switch (modulo){
case 0:
rec4 = line_crnt
load_fltr = substr(rec4, 2, 11) # PoD.
tbl_filter[load_fltr] = rec4
break
case 1:
rec1 = line_crnt
break
case 2:
rec2 = line_crnt
break
case 3:
rec3 = line_crnt
break
default:
print "line_cnt_in % NUM_RECS_INVC = " (line_cnt_in % NUM_RECS_INVC) >> JOB_OUT
exit
break
}
next
}
# For each line of input.
{
line_cnt_in += 1
line_crnt = $0
modulo = line_cnt_in % NUM_RECS_INVC
switch (modulo){
case 0:
rec4 = line_crnt
process_rec4(rec4, tbl_filter)
break
case 1:
rec1 = line_crnt
break
case 2:
rec2 = line_crnt
break
case 3:
rec3 = line_crnt
break
default:
print "line_cnt_in % NUM_RECS_INVC = " (line_cnt_in % NUM_RECS_INVC) >> JOB_OUT
exit
break
}
}
# After last line.
END {
print "" >> JOB_OUT
print "Read : line_cnt_fltr = @" line_cnt_fltr "@" >> JOB_OUT
print "Read : line_cnt_in = @" line_cnt_in "@" >> JOB_OUT
print "Writ : line_cnt_ot = @" line_cnt_ot "@" >> JOB_OUT
print "" >> JOB_OUT
print "GAwk Ended" >> JOB_OUT
}
以上是关于sh SAMPLE.AWK.CODES的主要内容,如果未能解决你的问题,请参考以下文章
如何使我的命令行在具有扩展名(.sh)和名称如“weird.sh.sh.sh”的文件上工作
sh sh_template.sh
sh sh.sh
Linux下面如何运行 SH文件
配置告警系统主脚本main.sh mon.sh load.sh 502.sh disk.sh
shell 脚本各种执行方式(source ./*.sh, . ./*.sh, ./*.sh)的区别