• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Command Line Text Deletion Utility Recommendation

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

zzzzzzzzzz

Member
Joined
Apr 7, 2009
I am looking for a utility that can run be used to delete from a text file, an entire line of text for which a text string is contained.

The utility must natively be supported natively on Windows 2000 family operating systems (so no .NET) and run on the command line (to be used in batch file scripting).

I have not been able to find such a utility.

What utility is recommended?
 
If you know some programming, this is easy.

Just read the input file one line at a time, and write it to an output file if it doesn't contain the string.
 
If you know some programming, this is easy.

Just read the input file one line at a time, and write it to an output file if it doesn't contain the string.
For some years, a long time ago I programmed in C++ (the simple stuff, not the large applications).

Now I am quite out of practice and would prefer to acquire a utility by other means than programming one.
 
Code:
#include <iostream>
#include <string>

int main(int argc, char **argv) {

    if (argc != 2) {
        std::cerr << "Usage: " << argv[0] << " token < inputfile > outputfile (will overwrite output file if it exists!)" << std::endl;
        return 1;
    }

    std::string line;

    while ( std::getline(std::cin, line) ) {
        if (line.find(argv[1]) == std::string::npos) std::cout << line << std::endl;
    }

}

Code:
g++ asdf.cpp -o delete_line
delete_line findme < input_file > output_file

Untested, but should work.
 
Code:
#include <iostream>
#include <string>

int main(int argc, char **argv) {

    if (argc != 2) {
        std::cerr << "Usage: " << argv[0] << " token < inputfile > outputfile (will overwrite output file if it exists!)" << std::endl;
        return 1;
    }

    std::string line;

    while ( std::getline(std::cin, line) ) {
        if (line.find(argv[1]) == std::string::npos) std::cout << line << std::endl;
    }

}

Code:
g++ asdf.cpp -o delete_line
delete_line findme < input_file > output_file

Untested, but should work.
Thanks.

I should have a copy of the Borland C++ installer; I may try this later.
 
Or just download MinGW. Borland C++ is ancient.

The 2 most popular compilers/IDEs are GCC (MinGW on Windows) and M$ Visual Studio. GCC is free and open source, VS has a free edition.
 
Back