#!/bin/bash
# 读取result.txt文件内容
while IFS= read -r line
do
if [[ $line == *"ORACLEDB"* ]]; then
ORACLEDB_line="$line" # 保存ORACLEDB行
else
# 提取POSTGRES行的表名和列值
table=$(echo "$line" | cut -d':' -f2)
columns=$(echo "$line" | cut -d':' -f4 | sed 's/[][]//g')
IFS='|' read -ra col_arr <<< "$columns"
# 提取ORACLEDB行的列值
ORACLEDB_columns=$(echo "$ORACLEDB_line" | cut -d':' -f4 | sed 's/[][]//g')
IFS='|' read -ra oracle_col_arr <<< "$ORACLEDB_columns"
# 将POSTGRES行中不同的列值替换为ORACLEDB行中对应的列值
for (( i=0; i<${#col_arr[@]}; i++ ))
do
if [[ "${col_arr[i]}" != "${oracle_col_arr[i]}" ]]; then
col_arr[i]=${oracle_col_arr[i]}
fi
done
# 打印结果
result=$(printf "%s:%s:%s:[%s|%s|%s|%s|%s|]\n" \
"$(echo "$line" | cut -d':' -f1)" \
"$(echo "$line" | cut -d':' -f2)" \
"$(echo "$line" | cut -d':' -f3)" \
"${col_arr[0]}" \
"${col_arr[1]}" \
"${col_arr[2]}" \
"${col_arr[3]}" \
"${col_arr[4]}")
echo "$result"
fi
done < result.txt
标签:cut,IFS,文本格式,echo,ORACLEDB,line
From: https://www.cnblogs.com/Jeona/p/18170352