【问题标题】:I am getting an error : syntax error at -e line 1, at EOF Execution of -e aborted due to compilation errors我收到一个错误:-e 第 1 行的语法错误,在 EOF 处 -e 的执行由于编译错误而中止
【发布时间】:2020-05-16 20:12:20
【问题描述】:

编写 perl 脚本是为了发送数据。 它正在抛出异常:

-e 第 1 行的语法错误,在 EOF 执行 -e 因以下原因中止 编译错误。

代码:

patln=`awk -v dat="$dt" '$0 ~ dat {print NR}' *path of the file where the logs are present*| head -1` 

STATUS=$( perl -ne "print if $. >= $patln" *path of the file where the logs are present* | grep TABLE

【问题讨论】:

  • 显示的代码有一个不平衡的括号,*path of the file where the logs are present* 不是真的存在,是吗?贴出真实代码。
  • 尝试在 perl 代码周围使用单引号而不是双引号?
  • 我尝试使用单引号..没有帮助。
  • 是的,日志文件存在。
  • 如何计算变量 $pathln ?如果将 Perl 脚本替换为 perl -ne "print" ... 是否还会出现语法错误?

标签: perl scripting


【解决方案1】:

不要尝试生成 Perl 代码!

# Use an env var.
export patln
perl -ne'print if $. >= $ENV{patln} && /TABLE/' -- "$LOG"

# Use an env var (expected to one process only).
patln="$patln" perl -ne'print if $. >= $ENV{patln} && /TABLE/' -- "$LOG"

# Use arguments (e.g. using -s)
perl -sne'print if $. >= $patln && /TABLE/' -- -patln="$patln" -- "$LOG"

# Perl not even needed here.
tail -n +"$patln"  -- "$LOG" | grep TABLE

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-20
    • 2019-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-27
    • 1970-01-01
    相关资源
    最近更新 更多