This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

file i/o qustion .. please help !!  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.
SudhaPrakash Madanambedu
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by 'take out' those lines? Do you want to print them on console or write them to a file?
Anyway, put down your code here, we can try to repair it.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!