Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to get the count of lines between specific loop

 
rahulJ james
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a file which will be in the below format.


where 000010 is the sum of rows between the record starting with ST and SE SE*000010*331052579, wherein my case it is 10. I need to have a script which can generate this value and replace the file with the correct count. I am getting files with an incorrect count as SE*000024*331052579. I need to have a script to calculate the segments between ^ST and ^SE inlcuding these 2 and poulate that count as SE*000010*331052579

Please advise and this is an urgent issue.. I am not an unix guy though I am assigned to this
 
Travis Hein
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about the thing that does the printing of this file out. I assume that you are printing each line out from a bean or some object source.

and you provide your own line counter variable.




what?

where FancyPrintStream is:



or if its not a PrintStream you are using, a print writer, a record writer, output stream, basically hook into every time you would render an "end of line" character and increment a line counter, over the span of that record, which you would reset after rendering a complete record.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11878
195
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Travis suggested, you need to read each line, look at what type of line it is (record start, record end, or record contents), and print out the appropriate response. You can then easily count line numbers yourself and verify whether they are correct or not. For example:

awk and perl are ideally suited to these sorts of tasks, which is why Unix administrators love this tools so much.
Please advise and this is an urgent issue..

Please ease up

I am not an unix guy though I am assigned to this

As Travis demonstrated, this can be solved using Java - no need to use Unix tools (although they are ideally suited to the task). Why are you getting assigned Unix tasks if you are not a Unix person?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic