Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

file i/o qustion .. please help !!

 
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
kklsfjsjisiof
fsifsfsjsjklfsklfj
skfkljsf
black box
4, iuwieuo, wour, 3943434
5, oiieq, 4874, 945848
oritr]iprit]r
trotirtrtoorotirit
trtrtioirt]irtiurtrr
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.
Regards
shalu
 
SudhaPrakash Madanambedu
Greenhorn
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic