[20210930]bbed讀取資料塊7 fffext.sh.txt

lfree發表於2021-10-08

[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 "\n\r" | \
    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 "\n\r" 刪除回車換行,這樣變為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)

--//說明跟以前的指令碼的輸出沒有任何不同.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2794827/,如需轉載,請註明出處,否則將追究法律責任。

相關文章