Solved

batch script to scan a txt file and then pipe the following line out to variable

Posted on 2009-04-10
3
442 Views
Last Modified: 2012-05-06
I need a batch script that can scan the contents of a text file for a specific word and then output the text in the following line.

e.g text file contains:
rsdhkjd
dsfhkjhdsf
hjdkhkjdsf
this is useful:
       i need this line only

i need to script to scan through the text file and output the line after the 'this is useful' line

ive tried to do this with for /f but cannot make it read the next line
0
Comment
Question by:paul_at_work
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 500 total points
ID: 24114821
Here's one possible solution:
@echo off
setlocal
set InFile=test.txt
set Search=This is useful:
 
set /a LineNumber = 0
for /f "tokens=1 delims=[]" %%a in ('type "%InFile%" ^| find /i /n "%Search%"') do set LineNumber=%%a
if %LineNumber%==0 (echo Search string not found!&goto :eof)
set /a LineNumber+=1
for /f "tokens=1* delims=[]" %%a in ('type "%InFile%" ^| find /v /n ""') do if "%%a"=="%LineNumber%" set Line=%%b
echo %Line%

Open in new window

0
 
LVL 2

Expert Comment

by:brislane
ID: 24114833
find "text you want" file.txt > output.txt
0
 

Author Closing Comment

by:paul_at_work
ID: 31568863
Thank you so much, perfect.
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is only natural that we all want our PCs to be in good working order, improved system performance, so that is exactly how programs are advertised to entice. They say things like:            •      PC crashes? Get registry cleaner to repair it!    …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question