This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Linux / UNIX and the fly likes how to get the count of lines between specific loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "how to get the count of lines between specific loop" Watch "how to get the count of lines between specific loop" New topic
Author

how to get the count of lines between specific loop

rahulJ james
Ranch Hand

Joined: Oct 03, 2008
Posts: 123
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

Joined: Jun 06, 2006
Posts: 161
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.


Error: Keyboard not attached. Press F1 to continue.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

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?


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to get the count of lines between specific loop
 
Similar Threads
Doubt about StringTokenizer !!
Extract string between two patterns
JMK MAKE
i cant crack this code
how to replace a string on a line irrespective of the position