walletInfo.sh

本文档展示了如何使用bash脚本读取文件,通过SQL查询2018年2月到3月期间特定用户ID的数据,并将结果写入CSV文件,涉及日期时间处理和数据库操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#!/bin/bash
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE-$0}")";pwd)
exec 1>>$CUR_DIR"/log/sh.log"
exec 2>>$CUR_DIR"/log/sh.log.wf"
 . ~/.bashrc
filename=$1
readfile=$CUR_DIR/var/${filename}
echo $datafile
currentdate=`date +'%Y%m%d'`
current=`date "+%Y-%m-%d %H:%M:%S"`
timeStamp=`date -d "$current" +%s`
# 将current转换为时间戳,精确到毫秒
# currentTimeStamp=$((timeStamp*1000+`date "+%N"`/1000000))
csvfile=$CUR_DIR/data/${currentdate}".csv"
# 读文件放入数组
arr=()
while read line
do
    arr[${#arr[*]}]=$line
done < $readfile
echo ${arr[@]}
# 遍历数组拼成字符串
uids=''
for i in ${arr[@]}
do
    uids="$uids$i,"
done
# 去掉最后一个逗号
uids=${uids%*,}
echo $uids
sql="select F_trans_buyer_user_id,count(1) as cnt from wallet.t_wallet_info where F_business_time>='2018-02-28' and F_business_time<='2018-03-28' and F_trans_buyer_user_id in ($uids) and F_business_type=5 group by F_trans_buyer_user_id"
echo $sql
ret=`echo -e ${sql} |gp_rd -t -A`
echo $ret
for var in $ret
do
    echo $var
    uid=`echo -e $var |awk -F '|' '{print $1}' `
    cnt=`echo -e $var |awk -F '|' '{print $2}' `
     if [ "$cnt"  = "" ]
        then
            cnt=0
     fi
     `echo -e "${uid}\t${cnt}" >> $csvfile`
done

# alias gp_rd='psql -h *.*.*.* -p 5432 -d gp_pay -U data_rd'

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值