当前位置: 动力学知识库 > 问答 > 编程问答 >

linux - What does this awk script do?

问题描述:

I have a script that I need to reverse engineer, but the script appears to be broken. Below is a segment of the script around where it breaks.

awk 'BEGIN{while ((getline line < "file1") > 0){F=../file2

With similar statements repeated one after the other. The obvious problem is that there's an opening ' and {, but no closing ones. I could try to fix this, but I don't really know what this is even trying to do. I have some experience with linux commands but not a whole lot.

  1. I understand that file2 is a file location, but what is F=?
  2. There's the beginning ', but why? Should there be a closing one somewhere, or should that not even be there in the first place?

Anyone know, or have any ideas, as to what this is supposed to be?

网友答案:

As far as I can tell, this awk line is broken in several ways.

  1. It should have a terminating ', the ''s wrap the command/script you pass to the awk command to run.
  2. F=../file1 looks like variable assignment, but it's unquoted so awk thinks you're attempting to write a regular expression, which is unterminated by a second /.
  3. There is no terminating }.

The script looks incomplete since it should break down to this:

# read from file1 until EOF
while ((getline line < "file1") > 0) {
    F="../file2"
    # what now?
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: