Page 1 of 1

Echo specified Line number data based on inout line number

Posted: 11 Aug 2010 23:22
by rahul
1) I would like to use a string which exist at n th line number of data file(file containing lines of words) .
2)And to parse the exact data what i need for further operations( ":" symbol to separate left and right data to use

Example:
File data as below:
-----------------------------FILE DATA_START-----------------------------
aASA
ASAS
ASAS
Name: Wireless 1111 (VE-OD-APSH) Mobilephone Broadcast Card-Mini AEMN (COM23)
ASASAS
ASASSSA
ASASSA
-----------------------------FILE DATA_ENd-----------------------------

1>In the above I need fourth line data .. Let us say if u say line number 4, i need to get that data
2>In the current line I need to split the data by symbol ":" , Left side and right side, which i can use for further operations. :idea:

Re: Echo specified Line number data based on inout line numb

Posted: 12 Aug 2010 01:57
by aGerman
Try

Code: Select all

@echo off &setlocal
for /f "usebackq skip=3 tokens=1* delims=:" %%a in ("text.txt") do (
  set "left=%%a"
  set "right=%%b"
  goto :exitFor
)
:exitFor
echo %left%
echo %right%
pause

or

Code: Select all

@echo off &setlocal
for /f "tokens=1* delims=:" %%a in ('more +3 "text.txt"') do (
  set "left=%%a"
  set "right=%%b"
  goto :exitFor
)
:exitFor
echo %left%
echo %right%
pause

Regards
aGerman