Hunter的大杂烩 技术学习笔记

December 9, 2014

bash shell script sample

Filed under: 技术话题 — hunter @ 2:54 pm

用来提取sql中的两个变量值

sql:UPDATE XXXX SET `SEQ` = ‘123456’, yyy=’xxx’ where SEQ = 123457
#!/bin/sh

int_regex=([0-9]+)

grep UPDATE pg.sql |grep HK_SAKCHMJSHH|while read line
do
first_seq_pos=`echo $line|awk ‘{print index($0,”x60SEQx60 = x27″)}’`
second_seq_pos=`echo $line|awk ‘{print index($0, “SEQ = “)}’`

if [ $first_seq_pos -ne $second_seq_pos ];then
((first_seq_pos=$first_seq_pos+9))
((second_seq_pos=$second_seq_pos+6))
first_seq=`echo $line |awk -v pos=”$first_seq_pos” ‘{print substr($0, pos, 8) }’`
second_seq=`echo $line |awk -v pos=”$second_seq_pos” ‘{print substr($0, pos, 8) }’`
echo $first_seq
if [[ $first_seq =~ ([0-9]+) ]];then
echo “match:”${BASH_REMATCH[1]}
fi
echo $second_seq
exit
fi

done

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress