Results 1 to 8 of 8
  1. #1
    Member
    Join Date
    Apr 2009
    Posts
    355

    Command Line Text Deletion Utility Recommendation

    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?

  2. #2
    Member
    Join Date
    May 2008
    Location
    Vancouver, BC
    Posts
    1,127
    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.

  3. #3
    Member Krogen's Avatar
    Join Date
    Aug 2006
    Location
    Underground
    Posts
    580
    sed: http://gnuwin32.sourceforge.net/packages/sed.htm

    It's a unix utility, but the link above contains Windows binaries. You need to know how to use regular expressions, which isn't that straightforward. But if you read up on it, I'm sure it will do more than you need.
    Gigabyte P55-UD3R
    Core i5 750 @ 4GHz
    HR-01 PLUS
    4GB Corsair 1600 RAM
    Galaxy 460GTX 768MB @ 900MHz core
    WD 640GB Black
    OCZ GameXStream 700W


    Heat

  4. #4
    Member
    Join Date
    Apr 2009
    Posts
    355
    Quote Originally Posted by cyberfish View Post
    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.

  5. #5
    Member
    Join Date
    Apr 2009
    Posts
    355
    Quote Originally Posted by Krogen View Post
    sed: http://gnuwin32.sourceforge.net/packages/sed.htm

    It's a unix utility, but the link above contains Windows binaries. You need to know how to use regular expressions, which isn't that straightforward. But if you read up on it, I'm sure it will do more than you need.
    Thanks. I shall have a look at the documentation.

  6. #6
    Member
    Join Date
    May 2008
    Location
    Vancouver, BC
    Posts
    1,127
    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.

  7. #7
    Member
    Join Date
    Apr 2009
    Posts
    355
    Quote Originally Posted by cyberfish View Post
    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.

  8. #8
    Member
    Join Date
    May 2008
    Location
    Vancouver, BC
    Posts
    1,127
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •