Reputation: 47
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.
Upvotes: 0
Views: 1840
Reputation: 70933
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.
Upvotes: 3
Reputation: 41234
This not effectively different from MC ND's solution - it's another option though: It's case sensitive at the moment but has a /i
switch to change that.
find /v "exporting" < abc.txt > def.txt
Upvotes: 2