我写道:
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:^语法错误
有人可以帮忙吗?
答案 0 :(得分: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中使用引号的另一个有用的帖子:
答案 1 :(得分:0)
你在单引号内写双引号是错误的。任何代码在单引号内写入第一个双引号。