Solved

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

Posted on 2009-04-10
3
437 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 83

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Can I legally transfer my OEM version of Windows to another PC?  (AKA - Can I put a new systemboard in my OEM PC?) Few of us are both IT and legal experts but we all have our own views of Microsoft's licensing rules and how they apply.  There are…
Sometimes people don't understand why download speed shows differently for Windows than Linux.Specially, this article covers and shows the solution for throughput difference for Windows than a Linux machine. For this, I arranged a test scenario.I…
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…

832 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