首页 > 其他分享 >QU

QU

时间:2024-04-24 23:00:11浏览次数:10  
标签:last postgres column echo QU txt POSTGRES


#!/bin/bash

# 过滤掉所有OK列以及以---开头的列到result1.txt文件中
grep -v -E "TABLE1: OK|--" data_validation.txt > result1.txt

# 提取ORACLEDB以及POSTGRES开头的列,按照原格式存储到temp1.txt文件中
grep -E "ORACLEDB:|POSTGRES:" data_validation.txt > temp1.txt

# 逐对比较相邻的ORACLEDB和POSTGRES行的最后一列
while read -r oracle_line && read -r postgres_line; do
  # 使用awk按照"|"分隔去掉最后一段
  oracle_last_column=$(echo "$oracle_line" | awk -F '|' '{$NF=""; print}')

  # 提取POSTGRES行的最后一列,并按照时区进行转换
  postgres_last_column=$(echo "$postgres_line" | awk -F '|' '{print $NF}')
  timezone=$(echo "$postgres_line" | awk -F '|' '{print $3}' | awk '{print substr($0, length($0) - 8, 3)}')

  # 检查日期格式是否合法
  if [[ "$postgres_last_column" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2} ]]; then
    converted_postgres_last_column=$(TZ="UTC$timezone" date -d "$postgres_last_column" +"%Y-%m-%d %H:%M:%S %z")

    # 比较ORACLEDB和转换后的POSTGRES行的最后一列
    if [[ "$oracle_last_column" == "$converted_postgres_last_column" ]]; then
      echo "Yes"
    else
      echo "No"
    fi
  else
    echo "Invalid date format: $postgres_last_column"
  fi
done < <(grep -E "ORACLEDB:|POSTGRES:" temp1.txt)

# 删除临时文件
rm temp1.txt

标签:last,postgres,column,echo,QU,txt,POSTGRES
From: https://www.cnblogs.com/Jeona/p/18156567

相关文章