Computing.Net > Forums > Programming > Batch file to give the line which contains th

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file to give the line which contains th

Reply to Message Icon

Name: SCMBUILD
Date: September 30, 2009 at 12:01:06 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

I have a text file which is a log file it contains the below data

----------------------------------------------------------text file data------------------------------------------------------------------
Y:\>copy "Y:\Version 1\BCS\006\NT\BCS_NT_61006.zip" "C:\Distribute\6.1\6.1.006.75660\WIN\x86\DBCS"
1 file(s) copied.

Y:\>copy "Y:\Version 2\BCS\007\NT\BCS_NT_61007.zip" "C:\Distribute\6.1\6.1.007.78630\WIN\x86\DBCS"
1 file(s) copied.

Y:\>copy "Y:\Version 3\BCS\008\NT\BCS_NT_61008.zip" "C:\Distribute\6.1\6.1.008.79681\WIN\x86\DBCS"
1 file(s) copied.

Y:\>copy "Y:\Version 4\BCS\009\NT\BCS_NT_61009.zip" "C:\Distribute\6.1\6.1.009.9002\WIN\x86\DBCS"
1 file(s) copied.

Y:\>copy "Y:\Version 5\BCS\010\NT\BCS_NT_61010.zip" "C:\Distribute\6.1\6.1.010.9002\WIN\x86\DBCS"
1 file(s) copied.

Y:\>copy "Y:\Version 1\BCS\022\NT\BCS_NT_61022.zip" "C:\Distribute\6.1\6.1.022.9002\WIN\x86\DBCS"
The system cannot find the file specified.

Y:\>copy "Y:\Version 1\BCS\023\NT\BCS_NT_61022.zip" "C:\Distribute\6.1\6.1.022.9002\WIN\x86\DBCS"
The system cannot find the file specified.

Y:\>copy "Y:\Version 1\BCS\024\NT\BCS_NT_61022.zip" "C:\Distribute\6.1\6.1.022.9002\WIN\x86\DBCS"
The system cannot find the file specified.

Y:\>copy "Y:\Version 1\BCS\025\NT\BCS_NT_61022.zip" "C:\Distribute\6.1\6.1.022.9002\WIN\x86\DBCS"
The system cannot find the file specified.

Y:\>copy "Y:\Version 1\BCS\026\NT\BCS_NT_61022.zip" "C:\Distribute\6.1\6.1.022.9002\WIN\x86\DBCS"
The system cannot find the file specified.

Y:\>copy "Y:\Version 1\BCS\027\NT\BCS_NT_61022.zip" "C:\Distribute\6.1\6.1.022.9002\WIN\x86\DBCS"
The system cannot find the file specified.

Y:\>copy "Y:\Version 1\BCS\028\NT\BCS_NT_61022.zip" "C:\Distribute\6.1\6.1.022.9002\WIN\x86\DBCS"
The system cannot find the file specified.

Y:\>copy "Y:\Version 1\BCS\029\NT\BCS_NT_61022.zip" "C:\Distribute\6.1\6.1.022.9002\WIN\x86\DBCS"
The system cannot find the file specified.
----------------------------------------------------------text file data------------------------------------------------------------------


I want a batch script or command which returns a line containing the search string


I am doing like this

findstr /b "The system Cannot" "c:\log.txt" > log.CSV

It is giving the output like the below one

The system cannot find the file specified.
The system cannot find the file specified.
The system cannot find the file specified.
The system cannot find the file specified.
The system cannot find the file specified.
The system cannot find the file specified.
The system cannot find the file specified.
The system cannot find the file specified.


but i want the output as
Y:\>copy "Y:\Version 1\BCS\022\NT\BCS_NT_61022.zip" "C:\Distribute\6.1\6.1.022.9002\WIN\x86\DBCS"
Y:\>copy "Y:\Version 2\BCS\023\NT\BCS_NT_61023.zip" "C:\Distribute\6.1\6.1.023.9004\WIN\x86\DBCS"
Y:\>copy "Y:\Version 3\BCS\024\NT\BCS_NT_61023.zip" "C:\Distribute\6.1\6.1.023.9004\WIN\x86\DBCS"
Y:\>copy "Y:\Version 4\BCS\025\NT\BCS_NT_61023.zip" "C:\Distribute\6.1\6.1.023.9004\WIN\x86\DBCS"
Y:\>copy "Y:\Version 5\BCS\026\NT\BCS_NT_61023.zip" "C:\Distribute\6.1\6.1.023.9004\WIN\x86\DBCS"
Y:\>copy "Y:\Version 6\BCS\027\NT\BCS_NT_61023.zip" "C:\Distribute\6.1\6.1.023.9004\WIN\x86\DBCS"
Y:\>copy "Y:\Version 6\BCS\028\NT\BCS_NT_61023.zip" "C:\Distribute\6.1\6.1.023.9004\WIN\x86\DBCS"
Y:\>copy "Y:\Version 6\BCS\029\NT\BCS_NT_61023.zip" "C:\Distribute\6.1\6.1.023.9004\WIN\x86\DBCS"

Can you please help me.

Thanks.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: September 30, 2009 at 12:37:12 Pacific
Reply:

@echo off > newfile & setLocal enableDELAYedexpansion

for /f "tokens=* delims= " %%a in (mylog) do (
set p=!c!
set c=%%a
echo !c! | find "The system cannot find the file specified" > nul
if not errorlevel 1 (
>> newfile echo !p!
)
)


=====================================
Helping others achieve escape felicity

M2


0

Response Number 2
Name: IVO
Date: September 30, 2009 at 12:40:39 Pacific
Reply:

@echo off & setlocal EnableDelayedExpansion
type nul > output.txt
set pre=
for /F "delims=" %%j in ('type "TextFile.txt"') do (
  set row=%%j
  set row=!row:the system cannot find=!
  if not "!row!"=="%%j" echo.!pre!
  set pre=%%j
) >> output.txt


0

Response Number 3
Name: SCMBUILD
Date: September 30, 2009 at 12:57:04 Pacific
Reply:

Hi IVO and Mechanix2Go,

Thanks for responding to my mail, IT worked great and very fast.

Thanks.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Batch file to give the line which contains th

Batch file to extract certain lines www.computing.net/answers/programming/batch-file-to-extract-certain-lines/17465.html

Batch file to copy the lines www.computing.net/answers/programming/batch-file-to-copy-the-lines/11114.html

Batch File To Delete Line www.computing.net/answers/programming/batch-file-to-delete-line/15539.html