有什么办法可以在两行中逐个查找相似词
Is there any way to Find similar words one below another in 2 lines
我们在 unix/windows 中有一个大文件。
里面的数据就像
update table tblName set col1='Test' where col1='Test1'
select * from a
select * from b
delete from tblName where col1='xyz'
select * from a
select * from b
select * from c
delete from tblName where col1='pqr'
select * from c
我想在 VI 或 Notepad++ 和任何其他编辑器中搜索 2 个或更多 select 语句依次出现的所有行。
例如
搜索应该找到
select * from a
select * from b
甚至
select * from a
select * from b
select * from c
但不是
select * from c (the last line)
有人可以帮忙吗?
您应该为此研究正则表达式。您应该检查您的文本编辑器使用的是哪个标准,您会在文档 (Notepad++, vim) 中找到在 vim 上,您也可以执行 :help pattern 来查找关于此的文档。在大多数文本编辑器中,此正则表达式应该有效:
(select \* from \w+\n){2,}
匹配形式为
的连续两行或多行
select * from (some variable made up of letters, numbers and underscores)
它将不匹配
select * from a where property = "foo"
在vim中,情况略有不同,您将不得不使用模式
\(select \* from \w\+\n\)\{2,\}
所以你可以做一些事情,比如替换那些行
:%s/\(select \* from \w\+\n\)\{2,\}/hey, two or more select statements were removed here\r/g
(注意,这些行将在整个文件中被替换,因此请检查您将丢失的内容)。
您可能还需要考虑更多细节,例如区分大小写与不区分大小写的搜索和空行。
- Ctrl+F
- 查找内容:
(^select \* from.*\R)(?1)+
- 取消选中匹配大小写
- 选中环绕
- 检查正则表达式
- 取消勾选
. matches newline
- 查找下一个
解释:
( # start group 1
^ # beginning of line
select \* from # literally
.* # 0 or more any character but newline
\R # any kind of linebreak (ie. \r, \n, \r\n)
) # end group 1
(?1)+ # repeat pattern defined in group 1, 1 or more times
我们在 unix/windows 中有一个大文件。 里面的数据就像
update table tblName set col1='Test' where col1='Test1'
select * from a
select * from b
delete from tblName where col1='xyz'
select * from a
select * from b
select * from c
delete from tblName where col1='pqr'
select * from c
我想在 VI 或 Notepad++ 和任何其他编辑器中搜索 2 个或更多 select 语句依次出现的所有行。
例如
搜索应该找到
select * from a
select * from b
甚至
select * from a
select * from b
select * from c
但不是
select * from c (the last line)
有人可以帮忙吗?
您应该为此研究正则表达式。您应该检查您的文本编辑器使用的是哪个标准,您会在文档 (Notepad++, vim) 中找到在 vim 上,您也可以执行 :help pattern 来查找关于此的文档。在大多数文本编辑器中,此正则表达式应该有效:
(select \* from \w+\n){2,}
匹配形式为
的连续两行或多行select * from (some variable made up of letters, numbers and underscores)
它将不匹配
select * from a where property = "foo"
在vim中,情况略有不同,您将不得不使用模式
\(select \* from \w\+\n\)\{2,\}
所以你可以做一些事情,比如替换那些行
:%s/\(select \* from \w\+\n\)\{2,\}/hey, two or more select statements were removed here\r/g
(注意,这些行将在整个文件中被替换,因此请检查您将丢失的内容)。
您可能还需要考虑更多细节,例如区分大小写与不区分大小写的搜索和空行。
- Ctrl+F
- 查找内容:
(^select \* from.*\R)(?1)+
- 取消选中匹配大小写
- 选中环绕
- 检查正则表达式
- 取消勾选
. matches newline
- 查找下一个
解释:
( # start group 1
^ # beginning of line
select \* from # literally
.* # 0 or more any character but newline
\R # any kind of linebreak (ie. \r, \n, \r\n)
) # end group 1
(?1)+ # repeat pattern defined in group 1, 1 or more times