#!/bin/bash
DIR_his=/home/riskIns/hisbackup/
while read line;do ##从平台流水号文件中逐行读取流水号
str1=${line:0:6} ##取出流水号前六位
str2=${line:0:25} ##取出每行中的交易流水号,否者每行会附带‘$’结尾符
file=${DIR_his}order_info_${str1}.sql ##根据流水号前六位确定交易文件
if [ ! -f $file ];then ##判断交易文件是否存在
echo "$file is not exist!"
exit 1
else
datagram=`grep $line $file` ##从交易文件中取出符合流水号的那行并输出到另外一个文件
echo $datagram >> result.txt
sleep 1
fi
done<plat_id.txt ##平台流水号文件
本文主要使用一下技巧:
1.使用while read line来遍历文本每一行
2.获取$str2的时候,文本每行会有$结尾符,因此不能直接使用行内容,需要使用字符串截取