powershell - 在PowerShell中删除特定行之后的所有行

标签 powershell text-extraction

我有这个.txt文件

ROTHSCHILD  = 81;        // Fondation Adolphe de Rothschild          ,                          2019
ONCOPOLE    = 82;        // Oncopole - Toulouse                      ,                          2019
GHRMSA      = 83;        // GHR  Mulhouse Sud-Alsace                 ,                          2019
CHDN        = 84;        // CH   du Nord - Luxembourg                ,                          2019
CAEN        = 85;        // CHU  de Caen                             ,                          2019
MONTELIMAR  = 86;        //                                          ,                          2019
PUYENVELAY  = 87;        //                                          ,                          2019

我要删除所有行
CHDN        = 84;        // CH   du Nord - Luxembourg                ,                          2019

我怎样才能做到这一点 ?

我尝试了这个:
get-content txt.txt | % {$_ ; if($_ -eq "CHDN        = 84;        // CH   du Nord - Luxembourg                ,                          2019") {break }}

但是中断程序,该怎么办?

最佳答案

您可能需要做一些每次测试的事情。我会这样使用Do..Until循环:

$txtData = get-content txt.txt
$stophere = 'CHDN        = 84;        // CH   du Nord - Luxembourg                ,                          2019'
$ctr = 0
Do
{
    $txtData[$ctr++] #Prints data line and increments counter
} Until ($txtData[$ctr] -eq $stophere)

关于powershell - 在PowerShell中删除特定行之后的所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60288428/

相关文章:

Python从段落中提取信息

powershell - 如何在 PowerShell 中正确/全局地转换 UTF-8(无 BOM)文件? (到另一个文件)

windows - midl 找不到 C 预处理器 cl.exe

javascript - 从网站上给定 SKU 编号列表中提取产品名称的最佳方法是什么?

python-3.x - tesseract中以下代码的字典输出的键值是什么意思?

php - 如何在php中提取字符串的一部分

powershell - 在 PowerShell 中读取 CSV 文件

Windows Server 2019 上的 Azure 管道 powershell 和 git 在输出中出现错误

powershell - 如何在PowerShell中对动态变量的内容进行转义?

python - 从二进制文件中提取文本(在Windows 7上使用Python 2.7)