我正在寻找一种方法,用awk直接在文件中替换使用awk找到的记录。因此Bash查找并替换awk文件中的记录
cat file
public function method1()
{
return 1;
}
/**
* old comment
*/
public function oldMethod()
{
return 'old';
}
public function method3()
{
return 3;
}
AWK返回
awk 'BEGIN{RS="\n\n"; IGNORECASE=1} /oldMethod/ {print $0}' file
/**
* old comment
*/
public function oldMethod()
{
return 'old';
}
UPDATE预期的输出例如为:
cat file
public function method1()
{
return 1;
}
/**
* new comment
*/
public function newMethod()
{
/*Do some fancy stuff here*/
return 'another output';
}
public function method3()
{
return 3;
}
现在我要替换此方法包含在一个变量的方法。 我不知道如何实现这一点。 有没有人一个好主意?
问候 nTOXIC
您的预期输出是什么? – 2015-03-13 10:29:12
在更换oldMethod() – nTOXIC 2015-03-13 10:32:28
后更新了我的请求,并更新了示例输出以更清晰地说明这不仅仅是替换单词部分的问题。 – nTOXIC 2015-03-13 11:12:24