Solved

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

Posted on 2009-04-10
3
439 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 84

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

730 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