[英]Increment a number in the “search and replace” function in Notepad++
I've got a big file with a regex filter. 我有一个带有正则表达式过滤器的大文件。 I'm converting it from a system to another, but it needs some modification.
我正在将其从一个系统转换为另一个系统,但需要进行一些修改。
Right now it looks like this: 现在看起来像这样:
{
"chatpattern" "MY REGEX FILTER"
}
But first I want to add a line inbetween the {
and the chatpattern
by doing the following in the search and replace function: 但是首先,我想通过在搜索和替换功能中执行以下操作,在
{
和chatpattern
添加一条线:
search: {
replace: { \r "TEXT" \r
And here comes the problem, after the first line I want the "TEXT"
to increment by 1, so it'll be like: 问题来了,在第一行之后,我希望
"TEXT"
增加1,所以它将像:
{
"TEXT1"
"chatpattern" "MY REGEX FILTER"
}
{
"TEXT2"
"chatpattern" "MY REGEX FILTER"
}
{
"TEXT3"
"chatpattern" "MY REGEX FILTER"
}
Is this possible? 这可能吗?
Here is a perl oneliner that does the job: 这是完成此工作的perl oneliner:
perl -pi.back -e 's/\{/"{\ntext".++$i/e;' in.txt
The substitution is done in place.>br> The original file is saved to in.txt.back
before processing. 替换就位完成。> br>在处理之前,原始文件已保存到
in.txt.back
。
Change the \\n
to whatever you want as line break. 将
\\n
更改为所需的换行符。
in.txt before: in.txt之前:
{
"chatpattern" "MY REGEX FILTER"
}
{
"chatpattern" "MY REGEX FILTER"
}
{
"chatpattern" "MY REGEX FILTER"
}
in.txt after: in.txt之后:
{
text1
"chatpattern" "MY REGEX FILTER"
}
{
text2
"chatpattern" "MY REGEX FILTER"
}
{
text3
"chatpattern" "MY REGEX FILTER"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.