Computing.Net > Forums > Programming > Possible to type, qgrep & rewrite on the fly?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Possible to type, qgrep & rewrite on the fly?

Reply to Message Icon

Name: nixah
Date: May 5, 2009 at 13:32:55 Pacific
OS: Windows XP
CPU/Ram: 4GB
Subcategory: Batch
Comment:

I frequently need to qgrep lines containing text that matches a specific criteria from one or more files. What bothers me is that a temp file needs to be created evey time to do this. For instance:
I have a 500 line file and 50 of those lines contain information about "YellowSumbmarine". I need to remove all lines containing "YellowSubmarine" altogether without leaving blank spaces where the text was removed.

My current process works, but requires creating a new file. For example:

for /F "usebackq" %i in (`dir /b "\\path\to\location\"`) do
   for /F "usebackq" %j in (`dir /b "\\path\to\location\%i\*.filetype"`) do 
      type "\\path\to\location\%i\%j" | qgrep -v YellowSubmarine >> \\path\to\location\%i\%j2

This is what 'file.filetype2' looks like after running the code:

BLEH Blah Blue
BLEH Blah Blue
BLEH Blah Blue

BlueSubMarine
OrangeSubmarine

RedSubmarine
PurpleSubmarine
BLEH Blah Orange
BLEH Blah Orange

Orange
etc...


This works, but not without creating a new file, file.filetype2, & there are now blank lines in the places where the lines of text I don't want were removed. This now means I need to clean it up:

for /F "tokens=* delims= " %i in (\\path\to\location\file.filetype2) do echo %i > \\path\to\location\file.filetype

Now, file.filetype contains the needed output:

BLEH Blah Blue
BLEH Blah Blue
BLEH Blah Blue
BlueSubMarine
OrangeSubmarine
RedSubmarine
PurpleSubmarine
BLEH Blah Orange
BLEH Blah Orange
Orange
etc...

I have what I need, but now I need to remove any instances of file.filetype2. While this works, it seems clumsy and inefficient. Is there a better way to do it without having to use multiple files?

Why can't we just `type` a file, `qgrep` it for 'whatever' & rewrite it on the fly without creating a new file. Couldn't we do something like:

type c:\qmail.log | qgrep -v "efnet" > c:\qmail.log



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


VBA code needed need a program



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Possible to type, qgrep & rewrite on the fly?

Editing the Registry on the fly www.computing.net/answers/programming/editing-the-registry-on-the-fly/11492.html

2D to 3D www.computing.net/answers/programming/2d-to-3d/14832.html

Detecting audio on the microphone www.computing.net/answers/programming/detecting-audio-on-the-microphone/13690.html