how to fetch rows based on line numbers or based on the beginning of a word
Joined: Oct 03, 2008
I have a file which will have rows like shown below,
The user will be entering an account number 2222234444 and I have a script which will get the RMR record which holds that account number and which will be displayed to the user for editing, something like,
Now the user wants the rows under RMR as well, display the RMR and the following segments until the next RMR is located. something like,
I thought of doing it by finding the line numbers of RMR and the next RMR and copying those records. Please advise me with an optimized solution
Joined: Mar 22, 2005
Assuming that there are line endings between the lines (and thus you can use a Reader to handle the lines), you could just read the file line by line until a line contains the RMR you're looking for, and then read the next line as well.
It would be helpful if you acknowledged responses that you get so that we know whether they are helpful or not.
For example, I can suggest that a command such as:
will probably do what you want.
However without any acknowledgment of previous posts, I do not know if you are interested in awk solutions, or whether you require perl solutions or php solutions or ???
Likewise, I threw that command line together in around 30 seconds. I could probably make it a lot easier to read and understand, but there is no point for me to do that at present since I have no idea whether you are interested in learning from this.