string selection in dos

November 8, 2011 at 09:04:38
Specs: Windows XP
hi i have one text file and in this file i have to select lines that does not start with the string 405 and the output i should get in a specified file.

eg.
405044000872764 919043906432 355728025755860 2010-02-09 08:00:57+05:30 Detached 405035-0ed8-6626
405035000653684 919037589699 358400006297480 2010-02-09 08:37:28+05:30 Attached 405035-0ce4-6681
405035000484120 919037457178 352938028504180 2010-02-09 08:27:32+05:30 Attached 405035-04b0-696d
502122347129103 60123164270 358726027284680 2010-02-09 09:06:58+05:30 Attached 405035-0ce4-8f84
502162911117974 60166134064 358995018945120 2010-02-09 09:57:38+05:30 Attached 405035-0dac-725f

and also i ahve to find the count of lines having the string word attached


See More: string selection in dos

Report •


#1
November 8, 2011 at 13:33:41
@echo off & setlocal EnableDelayedExpansion
for /F "delims=" %%j in ('type "Your_File.txt"') do (
  set line=%%j
  if not "!line:~0,3!"=="405" echo.!line!>> "Your_Output.txt"
)
for /F %%j in ('type "Your_Output.txt" ^| find /C /I "attached"') do (
  echo.  There are %%j lines holding "attached"
)

By the way this NT batch since there is no DOS at all in Windows XP.


Report •
Related Solutions


Ask Question