Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/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
Shell 如何在匹配模式后插入字符串_Shell - Fatal编程技术网

Shell 如何在匹配模式后插入字符串

Shell 如何在匹配模式后插入字符串,shell,Shell,我有许多文件,其内容如下: Class ABC { ... function getname(userid) { ... ... } function getprice(itemid,colorcode) { ... ... } } 我想向文件中添加测试点,以检查函数是否已被调用,因此,新文件应该如下所示,假设本例的文件名为/var/www/html/test.php: Class ABC { ... function

我有许多文件,其内容如下:

Class ABC
{
  ...

  function getname(userid)
  {
    ...
    ...
  }

  function getprice(itemid,colorcode)
  {
    ...
    ...
  }
}
我想向文件中添加测试点,以检查函数是否已被调用,因此,新文件应该如下所示,假设本例的文件名为/var/www/html/test.php:

Class ABC
{
  ...

  function getname(userid)
  {
    echo /var/www/html/test.php getname(userid) is called
    ...
  }

  function getprice(itemid,colorcode)
  {
    echo /var/www/html/test.php getprice(itemid,colorcode) is called
    ...
  }
}
字符串“echo{file name}{function name}被调用”将添加到文件中每个函数的开头

如何做到这一点?

解决方案:

$ txr addecho.txr data Class ABC { ... function getname(userid) { echo /var/www/html/test.php getname(userid) is called ... ... } function getprice(itemid,colorcode) { echo /var/www/html/test.php getprice(itemid,colorcode) is called ... ... } }
数据的内容与问题完全相同

@(repeat) @ (cases) function @name(@args) { @ (output) function @name(@args) { echo /var/www/html/test.php @name(@args) is called @ (end) @ (or) @line @ (do (put-line line)) @ (end) @(end)