[20210930]bbed读取数据块7 fffext.sh.txt
--//一般bash shell脚本很少考虑执行效率,仅仅考虑利用它快速解决工作中遇到的问题.
--//以前写的bbed读取数据块的脚本调用bbed次数太多,尝试改进脚本,减少bbed的调用次数.
$ cat -v fffext.sh
#! /bin/bash -x
# argv1=file_number argv2=begin_block argvs3=end_block argv4=data_object_id argv5=bbed /x format
#set -x
file_number=$1
begin_block=$2
end_block=$3
data_object_id=$4
ff="/r"${5}
# create sed script.
a=$5
len=$( echo ${#a} )
seq $len | xargs -IQ expr substr $a Q 1 | grep -n '[nt]' | sed 's+:.$+s/ $//+' >| ff.sed
echo 's+^*NULL*$++g' >> ff.sed
# scan begin_block to end_block,define search scope.
/bin/rm scan1.txt 2>/dev/null
seq -f "%-1.0f" $begin_block $end_block | xargs -IQ echo -e "host echo $file_number,Q np /d dba $file_number,Q ktbbh.ktbbhsid.ktbbhod1" |
rlbbed | grep "^BBED" | egrep "$file_number,|ub4 ktbbhod1" | awk '{print $NF}' | paste -d" " - - | awk -v a=$data_object_id '$2==a {print $1}' >| scan1.txt
# scan2 kdbr and display record.
cat scan1.txt |while read dba
do
#echo $dba
kdbr_size=$(echo p dba $dba kdbt[0].kdbtnrow | rlbbed| grep kdbtnrow | awk '{print $NF}')
#echo $kdbr_size
begin=0
end=$[ kdbr_size -1 ]
#echo $begin $end
#echo set dba $dba
IFSOLD=$IFS
echo p dba $dba offset 0 kdbr | rlbbed | grep "sb2 kdbr" | sed "1s/^BBED> //" | awk -F"[][ ]+" -v a=$kdbr_size '$NF > a {print $3}' |
sed "s+^+x $ff dba $dba *kdbr[+;s+$+]+"| rlbbed | sed -n '/^col /,/^BBED> /{s/^col .{13}: /^G/;/^$/d;/^BBED> /s/^.*$/^F/;p;}'| tr -d "nr" |
awk 'BEGIN{RS="^F"} {print $0}' | while read line
do
echo "$line" | sed "s/^G//" | tr "^G" "n" | sed -f ff.sed| paste -sd"|"
done
done
--//注意^G,^F的输入.linux下ctrl+v ctrl+g,ctrl+v ctrl+f. windows下ctrl+q ctrl+g,ctrl+q ctrl+f.
--//简单说明,不然自己以后都读不懂源代码: 生成的ff.sed脚本主要使用sed解决输出信息中数字,日期结尾存在空格问题以及NULL字段问题.
--//seq -f "%-1.0f" $begin_block $end_block 主要因为一些版本seq 在大于1e6时显示科学记数问题.
$ seq 4000000 4000001
4e+006
4e+006
$ seq -f "%-1.0f" 4000000 4000001
4000000
4000001
--//sed -n '/^col /,/^BBED> /{s/^col .{13}: /^G/;/^$/d;/^BBED> /s/^.*$/^F/;p;}'
--//使用bbed x命令的输出,替换类似col 0[3] @8153: 使用^G,并作为字段分隔符,替换^BBED>开头的行使用^F,并作为记录分隔符,并输出.
--//使用tr -d "nr" 删除回车换行,这样变为1行.过滤awk定义RS="^F",这样read line就仅仅接收1条记录.
--//scan begin_block to end_block,define Scope.调用bbed仅仅1次.
--//数据块扫描 调用bbed每块3次.
$ . fffext.sh 4 151 151 87108 nccntnnn
7369|SMITH|CLERK|7902|1980-12-17 00:00:00|800||20
7499|ALLEN|SALESMAN|7698|1981-02-20 00:00:00|1600|300|30
7521|WARD|SALESMAN|7698|1981-02-22 00:00:00|1250|500|30
7566|JONES|MANAGER|7839|1981-04-02 00:00:00|2975||20
7654|MARTIN|SALESMAN|7698|1981-09-28 00:00:00|1250|1400|30
7698|BLAKE|MANAGER|7839|1981-05-01 00:00:00|2850||30
7782|CLARK|MANAGER|7839|1981-06-09 00:00:00|2450||10
7788|SCOTT|ANALYST|7566|1987-04-19 00:00:00|3000||20
7839|KING|PRESIDENT||1981-11-17 00:00:00|5000||10
7844|TURNER|SALESMAN|7698|1981-09-08 00:00:00|1500|0|30
7876|ADAMS|CLERK|7788|1987-05-23 00:00:00|1100||20
7900|JAMES|CLERK|7698|1981-12-03 00:00:00|950||30
7902|FORD|ANALYST|7566|1981-12-03 00:00:00|3000||20
7934|MILLER|CLERK|7782|1982-01-23 00:00:00|1300||10
$ diff <(. fffext.sh 4 151 151 87108 nccntnnn) <(. fff.sh 4 151 151 87108 nccntnnn)
--//说明跟以前的脚本的输出没有任何不同.
文章来源: 博客园
- 还没有人评论,欢迎说说您的想法!