gpt4 book ai didi

linux - shell脚本中的新行

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:00:45 25 4
gpt4 key购买 nike

我的 shell 脚本中有以下命令,用于在一封电子邮件中发送所有四个 echo 语句

{
echo "Data Successfully loaded into LIP table"
echo "Total Items Purchased: `echo $QUERY1 | awk '{print $1}'`"
echo "Total Items MissingorMismatch: `echo $QUERY1 | awk '{print $2}'`"
echo "Error Percentage: $QUERY2"
} | mailx -s "Report for $DATE_YEST_FORMAT1" -r rj@host.com user2@host.com

但是当我看到我的电子邮件时,我得到了如下所示的输出,这是我不想要的-

Data Successfully loaded into LIP table Total Items Purchased: 3956391 
Total Items MissingorMismatch: 975825 Error Percentage: 24.66452380464924

我需要逐行输出类似下面的内容。

Data Successfully loaded into LIP table 
Total Items Purchased: 3956391
Total Items MissingorMismatch: 975825
Error Percentage: 24.66452380464924

有什么建议为什么会这样吗?我正在运行 SunOS (Solaris)

更新:-

尝试了 Kevin 的建议后

QUERY1=`hive -e "
set mapred.job.queue.name=hdmi-technology;
SELECT SUM(total_items_purchased), SUM(total_items_missingormismatch) from lip_data_quality where dt='$DATE_YEST_FORMAT2';"`

QUERY2=`hive -e "
set mapred.job.queue.name=hdmi-technology;
SELECT 100 * SUM(total_items_missingormismatch*1.0) / SUM(total_items_purchased) FROM lip_data_quality where dt='$DATE_YEST_FORMAT2';"`


mailx -s "LIP Data Quality Report for $DATE_YEST_FORMAT1" -r rj@host.com rj@host.com uname@host.com <<EOF
Data Successfully loaded into LIP_DATA_QUALITY table

Total Items Purchased: $(echo $QUERY1 | awk '{print $1}')

Total Items MissingorMismatch: $(echo $QUERY1 | awk '{print $2}')

Error Percentage: $QUERY2
EOF

我在电子邮件中收到的输出-

Data Successfully loaded into LIP_DATA_QUALITY table

Total Items Purchased: $(echo 3712928 393455 | awk '{print }')

Total Items MissingorMismatch: $(echo 3712928 393455 | awk '{print }')

Error Percentage: 10.596892802661404

这是不对的..我应该得到这样的输出-

Data Successfully loaded into LIP_DATA_QUALITY table

Total Items Purchased: 3712928

Total Items MissingorMismatch: 393455

Error Percentage: 10.596892802661404

我正在运行 SunOS

bash-3.00$ uname -a
SunOS lvsaishdc3in0001 5.10 Generic_142901-02 i86pc i386 i86pc

最佳答案

mailx 可能会忽略单个换行符并用空行分隔段落,类似于 tex 和我们自己的 SO。

结合 heredoc

mailx -s "Report for $DATE_YEST_FORMAT1" -r rj@host.com user2@host.com <<EOF
Data Successfully loaded into LIP table

Total Items Purchased: `echo $QUERY1 | awk '{print $1}'`

Total Items MissingorMismatch: `echo $QUERY1 | awk '{print $2}'`

Error Percentage: $QUERY2
EOF

[看来您的 bash 无法识别 $(command) 语法,因此我已将其删除。]

[注意我刚刚测试过,Solaris 的 mailx 发送了一封格式与我输入的格式完全相同的电子邮件。但是,如果您的邮件阅读器以 HTML 模式显示,它可能会折叠空格并将其全部显示为一行。]

关于linux - shell脚本中的新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11910960/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com