Copy lines based a string to a new File

January 27, 2018 at 09:35:24
Specs: Windows 10
Hi All,

I have a comma delimited file (SourceStatus.txt) which has multiple lines with 4 columns, I am trying to check if the line as order issued ( sometimes there may be 1 or 2 space characters before the string example ( 1,2,3,Order Issued or 3,4,5, Order Issued), if yes then I am trying to copy the complete line to a seperae file ( FineStatus.txt) using the below script but it's not working.

Can any one please suggest what I am doing wrong.

@echo off
for /F"delims=;" %%a in ('findstr /m /i "Order Issued" e:\test2\SourceStatus.txt') do (
cho %%a > FineStatus.txt


Sample Data in SourceStatus.txt

1,2,3,Order Issued
3,4,5,Not Issued
3,4,6, Order Issued
5,6,7, NA

FInal Data which I am trying to get in FineStatus.txt

1,2,3,Order Issued
3,4,6, Order Issued

message edited by Simran_2003

See More: Copy lines based a string to a new File

Report •

January 27, 2018 at 19:12:23
@echo off
>finestatus echo orderno,orderdate,comm,status
for /F "tokens=1-4 delims=," %%a in ('find /i "Order Issued" e:\test2\SourceStatus.txt') do (
>>finestatus.txt echo %%a,%%b,%%c,%%d

Report •

January 27, 2018 at 19:49:06
I'm not sure about this obsession with FOR. It's useful, but it doesn't need to be used for everything.
< e:\test2\SourceStatus.txt SET /P header=
> FineStatus.txt ECHO.%header%
FINDSTR /I /C:"Order Issued" < e:\test2\SourceStatus.txt >> FineStatus.txt

How To Ask Questions The Smart Way

message edited by Razor2.3

Report •

January 27, 2018 at 21:19:02
Ha! yes, my first thought as well: just use 'find'.
I assumed that there were other data on the lines, and he only wanted the first four. Looking back, I see there were only four items per line in the sample. That mistaken perception was why I resorted to "for".
Simpler is always better. (at least until "the other shoe drops")

Report •
Related Solutions

Ask Question