简体   繁体   English

使用awk比较两个文件时文件名的语法错误

[英]Syntax error on file name when using awk to compare two files

I'm trying to use awk to print the lines contained in one file2 if the numbers in column 1 or 5 is in file1, but I'm getting a syntax error that I don't understand. 如果第1列或第5列中的数字在file1中,我尝试使用awk打印一个file2中包含的行,但是我遇到了我不理解的语法错误。

My input is: 我的输入是:

file1.dat file1.dat

1
3
4
6
8
13
14
25

etc...

file2.dat File2.DAT的

2 GLU 1 - 3 ARG 2
24 ASP 2 - 12 LYS 1
3 ASP 1 - 25 ARG 2
7 LYS 2 - 17 GLU 2
18 ARG 1 - 13 GLU 2

etc...

In this case I want the output 在这种情况下,我需要输出

2 GLU 1 - 3 ARG 2
3 ASP 1 - 25 ARG 2
18 ARG 1 - 13 GLU 2

I tried to do this with the following awk-line 我试图用以下awk行来做到这一点

awk -F 'NR==FNR{a[$1||$5]++;next} (a[$1||$5])' file1.dat file2.dat

but I get the error 但我得到了错误

awk: file1.dat
awk:      ^syntax error

Does anyone know what is causing this error? 有谁知道是什么原因导致此错误? I have tried to put the file names into variables but that produces the same error. 我试图将文件名放入变量,但这会产生相同的错误。

You have supplied the -F flag for field separator. 您已为字段分隔符提供了-F标志。 The next argument is therefore the fields separator (which is your script because you didn't supply a seperator). 因此,下一个参数是字段分隔符(这是您的脚本,因为您没有提供分隔符)。 So awk takes the first file as the script itself. 因此,awk将第一个文件作为脚本本身。

Try to either drop the -F or adding a separator eg awk -F '[ \\t]*' '...' file1 file2 . 尝试删除-F或添加分隔符,例如awk -F '[ \\t]*' '...' file1 file2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM