如何使用dc_shell中的/ bin / sed命令删除与下一行中调用的下一个新模式匹配的模式

问题描述 投票:1回答:2

以下是我的文件示例,

         signal {
          {
            ab
            cd
          }

        "m_1_clk" {
              P {
                 '0ns' D;
                  '25ns' U;
                  '65ns' D;
                  }
             }

            "m_0_clk" {
                        P {
                          '0ns' D;
                          '25ns' U;
                          '65ns' D;
                          }
                       }

              "o_[9]" {
                     Data S Mk {
                     Active Up;
                            }
                        }

               "m_0_clk" {
                          Data S Mk {
                            Active Up;
                            }
                        }

             "m_1_clk" {
                          Data S Mk {
                          Active Up;
                            }
                        }
            }

我期待上面文件的输出是:

      signal {
           {
              ab
              cd
            }
         "o_[9]" {
                  Data S Mk {
                  Active Up;
                      }
                   }
              }     

嗨,上面是我的文件的示例我想删除模式,该模式匹配下一行中调用的下一个模式。

尝试搜索特定模式以删除不应出现在我的文件中的行。

需要在下一行中使用新模式搜索特定模式。因为第一行是在多个循环中调用。所以应该grep所有内容的具体模式。我尝试在tcl中使用下面的命令它不起作用。有谁可以帮我这个,

下面是tcl中使用的sed命令

exec /bin/sed -e {s/\m\(.*\)clk" {\.*\n\.*Data\.*//}  -i file

exec /bin/sed -e {s/\m\(.*\)clk" {\.*\n\.*P {\.*//}  -i  file
perl sed tcl
2个回答
0
投票

您能否请尝试关注并告诉我这是否对您有帮助。(考虑到您的实际Input_file与显示的示例文件相同)

awk -v line_number=$(cat Input_file | wc -l) '/signal {/ || /"o_\[9\]" {/ || FNR==line_number{flag=1}; /^$/{flag=""} flag'    Input_file

说明:现在也为代码添加说明,如下所示:

awk -v line_number=$(cat Input_file | wc -l) '   ##Creating variable named line_number in awk script whose value is number of lines of Input_file.
/signal {/ || /"o_\[9\]" {/ || FNR==line_number{ ##checking condition here if a line contains strings either signal {  OR "o_\[9\]" { then do following:
  flag=1}                                        ##Setting variable named flag here and setting its value to 1 here.
/^$/{                                            ##Checking condition here if a line is NULL or BLANK then do following:
  flag=""}                                       ##Nullifying the variable flag here.
flag                                             ##awk works on method of condition then actions, so checking if variable flag value is NOT NULL here and not mentioning any action here so by default peint of current line will happen here.
'   Input_file                                   ##Metioning the Input_file name here.

0
投票

使用上下文相关解析器的解决方案:

use Marpa::R2 qw();

my $input = <<'INPUT';
         signal {
          {
            ab
            cd
          }

        "m_1_clk" {
              P {
                 '0ns' D;
                  '25ns' U;
                  '65ns' D;
                  }
             }

            "m_0_clk" {
                        P {
                          '0ns' D;
                          '25ns' U;
                          '65ns' D;
                          }
                       }

              "o_[9]" {
                     Data S Mk {
                     Active Up;
                            }
                        }

               "m_0_clk" {
                          Data S Mk {
                            Active Up;
                            }
                        }

             "m_1_clk" {
                          Data S Mk {
                          Active Up;
                            }
                        }
            }
INPUT

my $grammar = Marpa::R2::Scanless::G->new({
    bless_package => 'Foo',
    source => \<<'GRAMMAR',
        :default ::= action => [values] bless => ::lhs
        lexeme default = action => [ value ] bless => ::name latm => 1
        :start ::= blocks
        blocks ::= block+
        block ::= optionalname [{] contentblocks [}] optionalws
        optionalname ::= name | epsilon
        contentblocks ::= contentorblock+
        contentorblock ::= content | block
        name ~ [a-zA-Z0-9_"\x{5b}\x{5d} ]+
        content ~ [a-zA-Z0-9;'\s]*
        optionalws ~ [\s]*
        epsilon ::=
GRAMMAR
});

my $parser = Marpa::R2::Scanless::R->new({grammar => $grammar});
$parser->read(\$input);
my $output;
deleteblocks($parser->value->$*);
print $output;

sub deleteblocks {
    my ($v) = @_;
    return if ref $v eq 'Foo::block' and $v->[0][0]
        and $v->[0][0][0] !~ /signal|"o_\[9\]"/;
    if (ref $v) {
        deleteblocks($_) for $v->@*;
    } else {
        $output .= $v || '';
    }
}

输出是:

     signal {
      {
        ab
        cd
      }

    "o_[9]" {
                 Data S Mk {
                 Active Up;
                        }
                    }

           }
© www.soinside.com 2019 - 2024. All rights reserved.