Echo specified Line number data based on inout line number

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
rahul
Posts: 7
Joined: 07 Aug 2010 01:18

Echo specified Line number data based on inout line number

#1 Post by rahul » 11 Aug 2010 23:22

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:

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

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

#2 Post by aGerman » 12 Aug 2010 01:57

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

Post Reply