簡體   English   中英

使用文件中的特定字符串跳過行-批處理腳本

[英]Skip line with a specific string from a file - Batch script

我正在嘗試使用Windows批處理腳本將abc.txt的一部分復制到def.txt文件。

的abc.txt

Connected to: Oracle Database 11g Enterprise Edition Release 
11.2.0.4.0 - 64bit Production. With the Partitioning, Automatic Storage
Management, OLAP, Data Mining and Real Application Testing options.

About to export specified tables via Conventional Path ...
... exporting table             table_1      2000 rows exported
..... exporting table             table_2        456512 rows exported
. . exporting table             table_3   So on...
Export successful with warnings. table_1 has some issue.

def.txt

Connected to: Oracle Database 11g Enterprise Edition Release 
11.2.0.4.0 - 64bit Production. With the Partitioning, Automatic Storage
Management, OLAP, Data Mining and Real Application Testing options.

About to export specified tables via Conventional Path ...
Export successful with warnings. table_1 has some issue.

簡而言之,我想跳過包含字符串“ exporting”的行,並將結果移至def.txt。 我嘗試將其for /F但無法實現。 能否請你幫忙。 提前致謝。

findstr /v /c:"exporting" abc.txt > def.txt

無需遍歷文件。 只需過濾輸入文件中與包含指示文字的條件不匹配的行( /v ),然后將輸出發送到指示文件。

編輯以適應評論

@echo off
    setlocal enableextensions disabledelayedexpansion
    > def.txt (
        for /f "tokens=1,* delims=:. " %%a in ('
            findstr /n "^" abc.txt
        ') do echo(%%b
    )

在這里,文件由findstr處理以對行進行編號(以保留源文件中的空行),由for /f命令處理的輸出帶有delimstokens子句,該子句配置為刪除輸出行中的起始空格/點/冒號。

這與MC ND的解決方案並沒有什么不同-盡管這是另一個選擇:目前區分大小寫,但是有一個/i開關可以更改它。

find /v "exporting" < abc.txt > def.txt

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM