First off , this isn’t a homework assignment!!! :p What I want to do is this:
Given a data file(be it text or numbers) saved on the desktop i.e., I want to be able to search that file and pull out only the data I want and print it to the screen. I may want to do other stuff with it but I have no idea what options there are.
Also, would python or c++ be more appropriate. I’m not familiar much with python and it’s been years since I’ve picked up c++ but I’ve heard that python is more efficient and although this program’s efficiency may or may not be a big deal I have heard python is much easier to understand.
Examples,Code, Templates(<– would be awesome)
Thanks all!
This is a bit difficult to answer without knowing how you want to specify the data you want.
If you can specify the necessary data using regexes, Python will probably be about equally efficient, and a bit quicker to write — but you may be able to do the job with something like grep even more easily.
If it’ll take a lot more processing to figure out what data to display, Python may start to get quite a bit slower — it can be quite fast as long as the Python part is mostly a fairly “thin” shell and most of the heavy lifting is done by various libraries. It can get quite a bit slower if you’re doing serious/significant processing in Python itself.
If you write in in C++, you’ll get more or less the opposite situation — as long as you’re reasonably careful, chances are pretty good that performance won’t be an issue. The real question will be how much work it takes to produce what you want. Without knowing anything about what data you’re looking for, how you want to display it, etc., it’s nearly impossible to guess about that though.
edit based on comment: A pattern like
Data = ####sounds like pretty much a classic case for a regular expression, for which grep will work just fine.This is also something Python can probably do perfectly well, but if you did decide to do your own in C++, it could look something like this:
This assumes you’re looking for the
Data = #pattern happening somewhere in the line. If you want to only consider it a match if that’s the whole line, change theregex_searchtoregex_matchinstead.The other assumption is that you’re using a relatively recent compiler that includes the standard regular expression classes. This is the case with VS 2010 and gcc 4.6 (if I recall correctly) but some older compilers may name it
std::tr1::regexinstead, and some that are older still won’t have it at all.