Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.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
Shell 在unix中打印行的一部分,直到指定的匹配数_Shell_Unix_Awk_Sed_Grep - Fatal编程技术网

Shell 在unix中打印行的一部分,直到指定的匹配数

Shell 在unix中打印行的一部分,直到指定的匹配数,shell,unix,awk,sed,grep,Shell,Unix,Awk,Sed,Grep,我有一个包含 aORbORcORdORe 1或3或4或6或8或10或11或 1或3或4或5或6 1或3或4或5或 豪猪 1或3或4或5或6或7或 你好!你好 莫托尔库芬酒店 豪猪 我能够grep包含或的行,并计算出现的次数。但现在我想 grep将该文件中包含超过5或s的行转换为另一个名为output.txt的文件。 所以output.txt包含 1或3或4或5或6 1或3或4或5或 1或3或4或5或6或7或 你好!你好 在output.txt中,指定3或-->它应显示行,直到出现5或5次 1

我有一个包含

aORbORcORdORe
1或3或4或6或8或10或11或
1或3或4或5或6
1或3或4或5或
豪猪
1或3或4或5或6或7或
你好!你好
莫托尔库芬酒店
豪猪
我能够grep包含或的行,并计算出现的次数。但现在我想

  • grep将该文件中包含超过5或s的行转换为另一个名为output.txt的文件。 所以output.txt包含

    1或3或4或5或6
    1或3或4或5或
    1或3或4或5或6或7或
    你好!你好
    
  • 在output.txt中,指定3或-->它应显示行,直到出现5或5次

    1或3或4
    1或3或4
    1或3或4
    你好
    
  • 在output.txt中,specity 7 or-->应显示直到7 or的行


  • 谢谢你的帮助

    使用
    awk

    任务1:

    awk -F 'OR' 'NF>5' file > output.txt
    
    cat output.txt
    1OR2OR3OR4OR5OR6OR7OR8OR10OR11OR
    1OR2OR3OR4OR5OR6
    1OR2OR3OR4OR5OR
    1OR2OR3OR4OR5OR6OR7OR
    helloORhiORhiORhiORhiORhi
    
    awk 'BEGIN{FS=OFS="OR"} {NF=4}1' output.txt
    1OR2OR3OR4
    1OR2OR3OR4
    1OR2OR3OR4
    1OR2OR3OR4
    helloORhiORhiORhi
    
    任务2:

    awk -F 'OR' 'NF>5' file > output.txt
    
    cat output.txt
    1OR2OR3OR4OR5OR6OR7OR8OR10OR11OR
    1OR2OR3OR4OR5OR6
    1OR2OR3OR4OR5OR
    1OR2OR3OR4OR5OR6OR7OR
    helloORhiORhiORhiORhiORhi
    
    awk 'BEGIN{FS=OFS="OR"} {NF=4}1' output.txt
    1OR2OR3OR4
    1OR2OR3OR4
    1OR2OR3OR4
    1OR2OR3OR4
    helloORhiORhiORhi
    

    欢迎来到SO,请展示您的编码工作,SO不是代码编写服务。对于第1部分,您可以使用
    For i in$(ls | grep OR);do[$(echo$“i”| grep-o或| wc-l)-gt 5]&&echo$“i”;完成>output.txt
    谢谢你,赛勒斯。下面是我迄今为止尝试的代码:#/垃圾箱/垃圾箱/bin/bash echo-e“Query\tOR\tAND\tfrom\tsize”>>读取行时测试;测试回波-n-n-e-n-e“t”>>>>测试回波-n-n-n-e-n-e“t”>>>>测试回波-n-e-n-e“\t”>>测试回波-n-n-e”\t”>>>测试回波-n-n-n-n-n-n-t“>>>测试回波-n-e”或“或”或“wc-l”或“wc-l”或“p-l”或“p-l”或“wc-l”或“wc-l”或“wc-l”或“wc-l”或“wc-l”或“wc-l”或“p-p-l”或“p-p-l”或“p-l”或“p-p-l”或“R”或“R”或“R”或“R”或”或”或”或“p-l”或”或“p-l”或“p-l e的/^.*(大小=)//p’| cut-d”和“-f1 | tr-d”\n'>>测试回波-n-e“\t”>>测试完成<80oct.csv谢谢你。我要试试这个,然后回来。