Notices

Overclockers Forums > Software > Programming Tips and Tricks
Programming Tips and Tricks
Forum Jump

Command Line Text Deletion Utility Recommendation

Post Reply New Thread Subscribe Search this Thread
 
 
Thread Tools
Old 11-22-09, 03:14 AM Thread Starter   #1
zzzzzzzzzz
Member



Join Date: Apr 2009

 
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?
zzzzzzzzzz is offline   QUOTE Thanks
Old 11-22-09, 04:04 AM   #2
cyberfish
Member



Join Date: May 2008
Location: Vancouver, BC

 
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.
cyberfish is offline Heatware Profile   QUOTE Thanks
Old 11-22-09, 09:06 AM   #3
Krogen
Member

 
Krogen's Avatar 

Join Date: Aug 2006
Location: Underground

 
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
Krogen is offline   QUOTE Thanks
Old 11-22-09, 01:45 PM Thread Starter   #4
zzzzzzzzzz
Member



Join Date: Apr 2009

 
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.
zzzzzzzzzz is offline   QUOTE Thanks
Old 11-22-09, 01:47 PM Thread Starter   #5
zzzzzzzzzz
Member



Join Date: Apr 2009

 
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.
zzzzzzzzzz is offline   QUOTE Thanks
Old 11-22-09, 02:14 PM   #6
cyberfish
Member



Join Date: May 2008
Location: Vancouver, BC

 
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.
cyberfish is offline Heatware Profile   QUOTE Thanks
Old 11-22-09, 03:08 PM Thread Starter   #7
zzzzzzzzzz
Member



Join Date: Apr 2009

 
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.
zzzzzzzzzz is offline   QUOTE Thanks
Old 11-22-09, 03:12 PM   #8
cyberfish
Member



Join Date: May 2008
Location: Vancouver, BC

 
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.
cyberfish is offline Heatware Profile   QUOTE Thanks

Post Reply New Thread Subscribe


Overclockers Forums > Software > Programming Tips and Tricks
Programming Tips and Tricks
Forum Jump

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Mobile Skin
All times are GMT -5. The time now is 07:39 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
You can add these icons by updating your profile information to include your Heatware ID, Benching Profile ID or your Folding/SETI profile ID. Edit your profile!
X

Welcome to Overclockers.com

Create your username to jump into the discussion!

New members like you have made this the best community on the Internet since 1998!


(4 digit year)

Why Join Us?

  • Share experience
  • Max out your hardware
  • Best forum members anywhere
  • Customized forum experience

Already a member?