Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unix awk比较7个文件,根据文件打印匹配和差异:_Unix_Awk - Fatal编程技术网

Unix awk比较7个文件,根据文件打印匹配和差异:

Unix awk比较7个文件,根据文件打印匹配和差异:,unix,awk,Unix,Awk,我需要将7个文件Ref.txt和Jan.txt复制到Jun.txt,并获取匹配项和非匹配项 我希望检查Ref.txt的第二个字段和Jan.txt到Jun.txt的所有第一个字段,如果是,则打印Ref.txt(主转储)的所有文件, 然后将整行Jan.txt打印到Jun.txt。如果在Jan.txt到Jun.txt上未找到匹配项,则表示“未找到” Ref.txt abc 10 xxyyzz bdc 20 xxyyzz edf 30 xxyyzz ghi 40 xxyyzz ofg 50 x

我需要将7个文件Ref.txt和Jan.txt复制到Jun.txt,并获取匹配项和非匹配项 我希望检查Ref.txt的第二个字段和Jan.txt到Jun.txt的所有第一个字段,如果是,则打印Ref.txt(主转储)的所有文件, 然后将整行Jan.txt打印到Jun.txt。如果在Jan.txt到Jun.txt上未找到匹配项,则表示“未找到”

Ref.txt

abc 10  xxyyzz
bdc 20  xxyyzz
edf 30  xxyyzz
ghi 40  xxyyzz
ofg 50  xxyyzz
mgf 60  xxyyzz
Jan.txt

10  Jan 100
30  Jan 300
50  Jan 500
二月号

10  Feb 200
20  Feb 400
40  Feb 800
60  Feb 1200
Mar.txt

20  Mar 600
50  Mar 1500
10  Apr 100
30  Apr 300
50  Apr 500
Apr.txt

20  Mar 600
50  Mar 1500
10  Apr 100
30  Apr 300
50  Apr 500
May.txt

10  May 200
20  May 400
40  May 800
60  May 1200
Jun.txt

20  Jun 600
50  Jun 1500
期望输出:

Ref.txt Ref.txt Ref.txt Jan.txt Jan.txt Jan.txt Feb.txt Feb.txt Feb.txt Mar.txt Mar.txt Mar.txt Apr.txt Apr.txt Apr.txt May.txt May.txt May.txt Jun.txt Jun.txt Jun.txt
abc 10  xxyyzz  10  Jan 100 10  Feb 200 Notfound    Notfound    Notfound    10  Apr 100 10  May 200 Notfound    Notfound    Notfound
bdc 20  xxyyzz  Notfound    Notfound    Notfound    20  Feb 400 20  Mar 600 Notfound    Notfound    Notfound    20  May 400 20  Jun 600
edf 30  xxyyzz  30  Jan 300 Notfound    Notfound    Notfound    Notfound    Notfound    Notfound    30  Apr 300 Notfound    Notfound    Notfound    Notfound    Notfound    Notfound
ghi 40  xxyyzz  Notfound    Notfound    Notfound    40  Feb 800 Notfound    Notfound    Notfound    Notfound    Notfound    Notfound    40  May 800 Notfound    Notfound    Notfound
ofg 50  xxyyzz  50  Jan 500 Notfound    Notfound    Notfound    50  Mar 1500    50  Apr 500 Notfound    Notfound    Notfound    50  Jun 1500
mgf 60  xxyyzz  Notfound    Notfound    Notfound    60  Feb 1200    Notfound    Notfound    Notfound    Notfound    Notfound    Notfound    60  May 1200    Notfound    Notfound    Notfound

提前感谢您的回复

这是一份礼物:如果您不懂,请提出问题

awk '
    FNR == 1 { 
        printf "%s %s %s\t", FILENAME, FILENAME, FILENAME 
        if (NR > FNR) file[++num_files] = FILENAME 
    }
    NR == FNR {
        id[NR] = $2
        ref[NR] = $0
        num_ids++
        next
    }
    { value[FILENAME,$1] = $0 }
    END {
        print ""
        for (row=1; row<=num_ids; row++) {
            printf "%s\t", ref[row]
            for (f=1; f<=num_files; f++) {
                key = file[f] SUBSEP id[row]
                printf "%s\t", (key in value ? value[key] : "Notfound")
            }
            print ""
        }
    }
' {Ref,Jan,Feb,Mar,Apr,May,Jun}.txt

这里有一个礼物:请问一些你不懂的问题

awk '
    FNR == 1 { 
        printf "%s %s %s\t", FILENAME, FILENAME, FILENAME 
        if (NR > FNR) file[++num_files] = FILENAME 
    }
    NR == FNR {
        id[NR] = $2
        ref[NR] = $0
        num_ids++
        next
    }
    { value[FILENAME,$1] = $0 }
    END {
        print ""
        for (row=1; row<=num_ids; row++) {
            printf "%s\t", ref[row]
            for (f=1; f<=num_files; f++) {
                key = file[f] SUBSEP id[row]
                printf "%s\t", (key in value ? value[key] : "Notfound")
            }
            print ""
        }
    }
' {Ref,Jan,Feb,Mar,Apr,May,Jun}.txt

这里有一个礼物:请问一些你不懂的问题

awk '
    FNR == 1 { 
        printf "%s %s %s\t", FILENAME, FILENAME, FILENAME 
        if (NR > FNR) file[++num_files] = FILENAME 
    }
    NR == FNR {
        id[NR] = $2
        ref[NR] = $0
        num_ids++
        next
    }
    { value[FILENAME,$1] = $0 }
    END {
        print ""
        for (row=1; row<=num_ids; row++) {
            printf "%s\t", ref[row]
            for (f=1; f<=num_files; f++) {
                key = file[f] SUBSEP id[row]
                printf "%s\t", (key in value ? value[key] : "Notfound")
            }
            print ""
        }
    }
' {Ref,Jan,Feb,Mar,Apr,May,Jun}.txt

这里有一个礼物:请问一些你不懂的问题

awk '
    FNR == 1 { 
        printf "%s %s %s\t", FILENAME, FILENAME, FILENAME 
        if (NR > FNR) file[++num_files] = FILENAME 
    }
    NR == FNR {
        id[NR] = $2
        ref[NR] = $0
        num_ids++
        next
    }
    { value[FILENAME,$1] = $0 }
    END {
        print ""
        for (row=1; row<=num_ids; row++) {
            printf "%s\t", ref[row]
            for (f=1; f<=num_files; f++) {
                key = file[f] SUBSEP id[row]
                printf "%s\t", (key in value ? value[key] : "Notfound")
            }
            print ""
        }
    }
' {Ref,Jan,Feb,Mar,Apr,May,Jun}.txt


感谢您回顾您的文章的可读性。感谢您提出的有趣问题。我们烦死了。为什么预期输出中没有
100年4月10日
?在预期输出中考虑到的Hi 100年4月10日,已经更改了预期输出,很抱歉,这项工作的100%正确工具是awk,您可以从Arnold Robbins的《有效的awk编程,第三版》一书中学习它。您也可以通过谷歌搜索示例,尤其是在comp.lang.awk新闻组上发布的任何内容。感谢您回顾您的文章的可读性。感谢您提出的有趣问题。我们烦死了。为什么预期输出中没有
100年4月10日
?在预期输出中考虑到的Hi 100年4月10日,已经更改了预期输出,很抱歉,这项工作的100%正确工具是awk,您可以从Arnold Robbins的《有效的awk编程,第三版》一书中学习它。您也可以通过谷歌搜索示例,尤其是在comp.lang.awk新闻组上发布的任何内容。感谢您回顾您的文章的可读性。感谢您提出的有趣问题。我们烦死了。为什么预期输出中没有
100年4月10日
?在预期输出中考虑到的Hi 100年4月10日,已经更改了预期输出,很抱歉,这项工作的100%正确工具是awk,您可以从Arnold Robbins的《有效的awk编程,第三版》一书中学习它。您也可以通过谷歌搜索示例,尤其是在comp.lang.awk新闻组上发布的任何内容。感谢您回顾您的文章的可读性。感谢您提出的有趣问题。我们烦死了。为什么预期输出中没有
100年4月10日
?在预期输出中考虑到的Hi 100年4月10日,已经更改了预期输出,很抱歉,这项工作的100%正确工具是awk,您可以从Arnold Robbins的《有效的awk编程,第三版》一书中学习它。你也可以用谷歌搜索一些例子,尤其是在comp.lang.awk新闻组上发布的任何东西。仍然令人费解的是,为什么OP的每一行预期输出都包含
1+6*3=19
元素(而您的解决方案包含
1+6=7
):+1个元素。仍然令人费解的是,为什么OP的每一行预期输出都包含
1+6*3=19
元素(而您的解决方案包含
1+6=7
):+1个元素。仍然令人费解的是,为什么OP的每一行预期输出都包含
1+6*3=19
元素(而您的解决方案包含
1+6=7
):+1个元素。为什么OP的每一行预期输出都包含
1+6*3=19
元素(而您的解决方案包含
1+6=7
)仍然令人费解: