在 Vim 中,我想用给定的字符串搜索行,然后删除它们。
具体来说,我想用 LaTeX 命令\begin{frame}和查找行\end{frame},然后删除它们。=
在linux中,在目录下的文件中查找所有出现的“string1”并将它们替换为“string2”的好方法是什么?
现在我正在用 vbscript 开发一个脚本,我需要在 5k 行源代码上找到一个特定的行(出现很多次)并将其替换为两个新的代码行(1 行到 2 行替换)。
我正在使用Notepad++,但就我的开发而言,我可以使用任何其他编辑器,有一天我可能会遇到编辑任何类型文本文件的相同问题。我已经尝试在 Notepad++、MS Word 甚至 Windows 记事本上找到一种方法,但没有找到任何解决方案(所有这些都只是用替换文本的第一行替换了搜索出现)。

在文本编辑器上找到带有Ctrl+F或Ctrl+的事件时,有什么方法可以将一个文本行替换为两行或更多行H?
我试图了解 Windows 批处理中的字符串替换实际上是如何工作的并且遇到了问题。
@echo off
set var=wild
set varnew=%var:l=n%
echo var is: %var%
echo varnew is: %varnew%
Run Code Online (Sandbox Code Playgroud)
确实有效;它生成预期的输出:
var is: wild
varnew is: wind
Run Code Online (Sandbox Code Playgroud)
但这不是(示例目录“Main”):
@echo off
for /D %%G IN (*) do (
setlocal
echo G is: %%G
set _srcp=%%G
echo _srcp is %_srcp%
rem set _newp=%_newp:ai=_01_% <-- confused variable
set _newp=%_srcp:ai=_01_%
echo._newp is: %_newp%
endlocal
)
Run Code Online (Sandbox Code Playgroud)
它生成此输出:
G is: Main
_srcp is Main
_newp is: %_srcp:ai=_01_
Run Code Online (Sandbox Code Playgroud)
我希望代码生_newp is: M_01_n成为最后一行。我在这里真的没有想法,有人可以指出我正确的方向吗?
BB
我知道以前可能有人问过这个问题,但我找不到答案。
我需要替换以下内容: CoverLevel="XX" 与 CoverLevel="0" ,这包括 XX 是任何数字,而不替换类似的实例,例如 CoverLevel="True" 或 CoverLevel 或 MinCoverLevel="1.3"
用记事本++可以吗?
我有一个 .xlf 文件,如下图所示:
我想知道如何搜索并将 unicode 字符"xE5"替换为"æ" 我以为我可以搜索:^0145 =xE5并替换"æ",这不起作用。
如果这是不可能的,我可以使用另一个文本编辑器(例如 Ultraedit)。
这是文件中粘贴的文本:
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-strict.xsd">
<file xmlns:bind="http://bind.sorona.se" original="CTO12623_1_en-GB-da.xml" source-language="en" datatype="xml" date="2015-11-11T15:35:51Z" target-language="da" product-name="Anders_LP8504_151111" bind:file-id="78452" bind:file-hash="85075c54359fa47b087d6c67ec967f43">
<header>
<tool tool-name="Sorona TMS" tool-id="bind" tool-version="3.1.5" tool-company="Sorona Innovation" />
<count-group name="word-count">
<count count-type="total" unit="word">2743</count>
</count-group>
</header>
<body>
<trans-unit id="e1ca41ef868a74944745b8cd1dfa59e7" translate="yes" approved="no" restype="string" resname="p">
<source>The trench compactor LP 8504 is a radio controlled trench compactor. It has a robust design and is suitable for …Run Code Online (Sandbox Code Playgroud) 在 Vim 中,我经常发现我只对包含特定文本字符串的行感兴趣,并想删除所有其他行。
匹配包含字符串的行很容易:
:s/^.*foo.*\n//
Run Code Online (Sandbox Code Playgroud)
我通常最终做的是两次传递,一次用特殊的第一个字符“标记”我想要的所有行:
:s/^\(.*foo.*\)$/X\1/
Run Code Online (Sandbox Code Playgroud)
在第二遍中,很容易对固定位置的一个字符进行否定匹配,因此我删除了所有没有字符串的行,因此:
:s/^[^X].*\n//
Run Code Online (Sandbox Code Playgroud)
但是,难道没有一种更直接的方法可以通过一次传递来做到这一点吗?我错过了什么?
是否有软件/脚本或任何方式可以自动替换her文档中的所有内容him以及his分别适用的地方?
例子
Calls her and tells her that her car is …
Run Code Online (Sandbox Code Playgroud)
到
Calls him and tells him that his car is …
Run Code Online (Sandbox Code Playgroud) 您能否帮助我找出如何使用 Notepad++ 查找/替换功能来替换特定单词之间的特定字符。请参见下面的示例,我想找到单词 'START' 和 'END' 之间的所有连字符并将它们替换为空格。文档中的所有其他连字符都不会被替换。
我一直在尝试使用我在 google 上搜索的正则表达式示例来解决这个问题,但不幸的是,到目前为止我还没有成功。
这是我所拥有的:
START-Hyphens-should-be-replaced-here-01-END
OTHER-no-changes-here-02-WORD
START-Hyphens-should-also-be-replaced-here-03-END
OTHER-no-changes-here-either-04-TEXT
Run Code Online (Sandbox Code Playgroud)
这是我想要的:
START Hyphens should be replaced here 01 END
OTHER-no-changes-here-02-WORD
START Hyphens should also be replaced here 03 END
OTHER-no-changes-here-either-04-TEXT
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 FART(查找和替换文本)来搜索字符序列,并且我同时使用了该--c-style选项(以便我可以\x2F用来表示正斜杠)和--word,因此我可以使用正则表达式。但是我无法让正则表达式起作用。
例如
fart --line-number --ignore-case --preview --c-style --word *.pas "\x2F\x2F.*hello"
Run Code Online (Sandbox Code Playgroud)
应该匹配并打印出以下行:
// hello
// well, hello there
Run Code Online (Sandbox Code Playgroud)
- 鉴于我对 RegExp 语法的理解(.匹配任何字符,*意味着“前一个字符出现零次或多次”),但它似乎不起作用。
有谁知道是否记录了正则表达式的语法?(或者也许--c-style和--word不兼容?)。
** 编辑 **
我应该指出,该实用程序findstr也可以完成我想要的工作,并且可能正确支持正则表达式,但真正有用的一点FART是它返回%ErrorLevel%. findstr仅在返回代码中返回“找到”或“未找到”。
find-and-replace ×10
regex ×4
notepad++ ×2
vim ×2
windows ×2
batch ×1
command-line ×1
linux ×1
search ×1
string ×1
text-editors ×1