Deleting/Gathering Text from File

Dec 23, 2009 at 6:48pm
Hi, I have a file in wordpad that I need to delete a few strips. Its about 500 pages long so I cannot do it manually (it takes forever). I kind of understand how do approach this with c++. Well here's an example:

? = random text

?????????????????????????????<LastName>Doe</LastName><FirstName>John</FirstName><SSN>123456789</SSN><SSNNA>0</SSNNA>?????????????????????????????

I want to keep the ??? and get rid of the text. Its repeted over and over throughout the body. Also the numbers change and the names change of course throughout.

Example:

while( getline(in,line) )
{
if(line != "I want to delete this line")
out << line << "\n";
}
in.close();
out.close();

(taken from: http://www.daniweb.com/code/post969008.html#)

Now for the if(line) part can I write if(line != "<LastName>" to "</SSNNA>")

to get rid of the whole chunk? or else how do I do that? Thank you.

Dec 23, 2009 at 7:56pm
You could use an editor with regular expressions.
Replace: (.*)\<LastName\>.*\<\/SSNNA\>(.*)
With: \1\2
Dec 23, 2009 at 8:05pm
Sorry I dont understand :(
Dec 23, 2009 at 8:37pm
You could use a text editor that supports regular expressions, such as Notepad++.
Dec 23, 2009 at 8:44pm
Idk how.
Dec 23, 2009 at 8:47pm
You don't know how to use a text editor?
Dec 23, 2009 at 8:54pm
no =(
Dec 23, 2009 at 9:02pm
do you know how to use a "keyboard"?
Dec 23, 2009 at 9:03pm
I... Uh... What? How is that possible? What do you write your code with, then?
Dec 23, 2009 at 9:12pm
i use my keyboard
Dec 23, 2009 at 9:18pm
Since you're being such a smartass, I guess you don't need any help. Good luck.
Dec 23, 2009 at 10:21pm
What im not being the smart ass you were? You aren't very helpful anyways.
Dec 24, 2009 at 2:30am
If your editor supports regular expressions, you can use its search and replace function
to find the text and replace it with nothing.

Helios suggested what you should enter as the search text.
The "replace with" text should be \1\2, which have special
meaning in regular expressions.

If you aren't following, then I'm guessing without looking that Wikipedia
will have a nice article on REs that will be a good primer for you.

Anyway, REs are probably what you want, whether you go with the editor-based
solution or a C++-based solution.
Dec 24, 2009 at 3:03am
Find What: (.*)\<LastName\>.*\<\/SSNNA\>(.*)

"Error: Search string not found!"

What do u mean
Dec 24, 2009 at 3:14am
Make sure you have enabled regular expressions...
Dec 24, 2009 at 3:19am
I did
Dec 24, 2009 at 4:08am
please help me : (
Dec 24, 2009 at 9:48am
You can do it from the command line.
grep -v "I want to delete this line" inputfile > outputfile
Dec 24, 2009 at 3:06pm
I can't get (.*)\<LastName\>.*\<\/SSNNA\>(.*) to work.
Topic archived. No new replies allowed.