I am trying to copy part of abc.txt to def.txt file using windows batch scripting.
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.
In short I want to skip the lines that are having the string "exporting" and move the result to def.txt. I tried using for /F
but could not acheive this. Could you please help. Thanks in advance.
findstr /v /c:"exporting" abc.txt > def.txt
No need to iterate over the file. Just filter the lines in the input file that does not match ( /v
) the condition of containing the indicated literal, and send the output to the indicated file.
edited to adapt to comments
@echo off
setlocal enableextensions disabledelayedexpansion
> def.txt (
for /f "tokens=1,* delims=:. " %%a in ('
findstr /n "^" abc.txt
') do echo(%%b
)
Here the file is processed by findstr
to number the lines (to preserver empty lines in source file), the output processed by a for /f
command with delims
and tokens
clauses configured to remove starting spaces/dots/colons in output lines.
这与MC ND的解决方案并没有什么不同-尽管这是另一个选择:目前区分大小写,但是有一个/i
开关可以更改它。
find /v "exporting" < abc.txt > def.txt
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.