Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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\%j2This 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.filetypeNow, 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

![]() |
VBA code needed
|
need a program
|

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