Solved

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

Posted on 2009-04-10
3
434 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
3 Comments
 
LVL 82

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
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
Comment Utility
find "text you want" file.txt > output.txt
0
 

Author Closing Comment

by:paul_at_work
Comment Utility
Thank you so much, perfect.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

cPanel is a Unix based web hosting control panel that provides a graphical interface and automation tools designed to simplify the process of hosting a web site. cPanel utilizes a 3 tier structure that provides functionality for administrators, rese…
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!    …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

772 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now