【问题标题】:Error while using multiple quotes [closed]使用多个引号时出错[关闭]
【发布时间】:2018-09-14 19:46:38
【问题描述】:

我写过:

ssh $ip_address "grep -i 20-10-2018 | awk -F "," '{print $2",""open_"$5}' result.csv" | while read line
do
        echo $Date":00:00",$line
done

这是抛出这个错误:

awk: {print ,open_} awk: ^ 语法错误

谁能帮忙?

【问题讨论】:

  • 你期望这个脚本在做什么?
  • 如果您告诉我们您的示例输入和输出,我们可以为您提供更多帮助,请使用 CODE TAGS {} 按钮将它们添加到您的帖子中。
  • 我想在 result.csv 文件中查找特定日期并打印出来@RavinderSingh

标签: linux bash shell quotes


【解决方案1】:

使用heredoc 到run your commands over ssh:

ssh "$ip_address" << 'EOF'                 # shell will pass the heredoc as is to ssh because the end marker EOF is in quotes
    grep -i 20-10-2018 result.csv |        # I guess you meant to pass result.csv to grep, rather than awk
    awk -F "," '{ print $2",open_"$5 }' |  # good to put the parts of the pipeline on different lines for better readability
    while read line; do
      echo $Date":00:00",$line             # not sure what you mean by $Date here - probably $(date)?
    done
EOF

我不确定您所说的echo $Date":00:00" 是什么意思。我把那部分完好无损。


查看这篇文章以了解如何引用 awk 命令:

另一篇关于在 shell 中使用引号的有用帖子:

【讨论】:

  • 谢谢。很有用
【解决方案2】:

你在单引号内写双引号是错误的。任何代码都在单引号内写第一个双引号。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 2019-05-29
    相关资源
    最近更新 更多