Solved Count number of lines up to a specific character

April 8, 2013 at 19:45:46
Specs: Windows 7
I'm new in batch. I think my question will be very simple for you. I need a batch script to count number of lines from the first line of a file up to a unique character "A015" which is contained into this file (this number should also be take account blank lines). Thank you.

See More: Count number of lines up to a specific character

Report •

#1
April 8, 2013 at 20:02:23
:: ===== script starts here ===============
::
:: tamo.bat 2013-04-09 9:55:53.37
@echo off & setLocal enableDELAYedeXpansioN

for /f "tokens=1* delims=[]" %%a in ('find /n "A015" ^< myfile') do (
set/a N=%%a-1
)
echo.!N!
::====== script ends here =================

=====================
M2 Golden-Triangle


Report •

#2
April 9, 2013 at 00:29:39
Having !N!, I'd like to go to this line number to start out my processing.

For that, i have written

more +!N! myfile>resultFile

no chance for me, it doesn't work. do you have any idea of what to do?
Thanks


Report •

#3
April 9, 2013 at 01:53:25
✔ Best Answer
With this in myfile:

This is my text and everytime this
% character appears I would like to insert a blank line before it.

apple
zzz "A015"
cherry
%berry

It outputs 4, which seems about right.

=====================
M2 Golden-Triangle


Report •

Related Solutions

#4
April 9, 2013 at 02:11:07
sorry for trouble, I had not stress in a good file;-)

Having !N!, I'd like to go to this line number to start out my processing.

For that, i have written

more +!N! myfile>resultFile

no chance for me, mine doesn't work. do you have any idea of what to do?
Thanks


Report •

#5
April 9, 2013 at 11:22:13
set /a N -= 1
for /f "skip=%N%" %%a in (myfile) do <whatever>

How To Ask Questions The Smart Way


Report •

Ask Question