• Post Reply Bookmark Topic Watch Topic
  • New Topic

file i/o problems  RSS feed

shalu sharma
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
My requirement is that i have a file eg : abc.txt, then I need to search the string 'black box'. let's say that i found 6 occurences of the string black box in my file abc.txt, now after this string black box, I have some text of type:
1, 2323, 9849438, 539039
2, 4394983, 494938, 4954095
3, 5o343049, 4934, 999349838
... and so on.
here I need to take out all the lines after string black box, which is not fixed there may be 10 or 20 lines. one more thing to note is that I have to only take out those after black box which have the value in next line always incremented by 1.
ie, if the sample file is of type :
black box
1, 3232, 32323, 32323, 54854
2, iuriu, 238372, 68685, 96589
3, uuery, 585, 459584, 59
black box
4, iuwieuo, wour, 3943434
5, oiieq, 4874, 945848
black box
6, iidsdjks, 88343, 95696586
7, iieuiure, 3847, 3943948
8, 73, itr, 849584, kkjfg
9, eirieu,iiuru, woeooiwe

So I don't have to take 'kklsfjsjisiof' after '3, uuery, 585, 459584, 59
also there is no fixed no of lines to expect after black box., it could vary. the only input the user would be providing is the filename and nothing else. so far I have been able to find all the occurences of string blackbox but am stuck after that.
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi shalu,
i can't produce the exact code right now but here is what i think about the algorithm...

here if you want 'not to' have "black box" work in the newly generated file please detect it and ignore it. don't append it to 'newFile' stringbuffer..
i hope this helps.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!