Re: findstr, for, or other command to do this?

From: wadester (null_at_devnull.net)
Date: 04/27/04


Date: Tue, 27 Apr 2004 15:21:29 -0500

In article <uoLcquILEHA.1312@TK2MSFTNGP12.phx.gbl>, noone@nowhere.com
wrote...
> Situation: I have a log file with many fields and lines. Each line has say
> a computername field. The same computername will be listed several times
> thoughout the file. What if I wanted a list of computer names from the file?
> meaning 1 instance of each name returned from a command?
>
> example: A log file has 2 fields. ComputerName and DLLVersion. I want to
> construct a command or batch file that will return a unique list of computer
> names that do not have a DLLVersion equal to 4.1.002. Just using the find
> command gets me close but its not a unique list. The same computer names
> will be listed multiple times.
>
> any input is appreciated. Thanks.

Here's a starting place, at least:

Input file in.txt:
computer1 1.0
computer2 2.0
computer1 1.0
computer2 2.0
computer1 3.0
computer2 3.0

Find all unique computer names not at v3.0:
==========================================
@echo off
setlocal enabledelayedexpansion

del tmp.$$$ >nul 2>&1
for /f "tokens=1" %%I in ('findstr /v "3.0" in.txt ^| sort') do (
echo %%I >> tmp.$$$
)

REM Parse thru the sorted temp file and compare each
REM line to the previous one
set oldline=.
for /f %%l in (tmp.$$$) do (
set line=%%l
if !line! NEQ !oldline! echo !line!
set oldline=!line!
)
==========================================

ws

-- 
I saw this in a movie about a bus that had to SPEED around a city, 
keeping its SPEED over fifty, and if its SPEED dropped, it would 
explode. I think it was called, "The Bus That Couldn't Slow Down."


Relevant Pages

  • Re: Network Copy Changing File Name to Something Unique (ex date a
    ... Comments and File Name to a log file I have in the store ... >>I cannot figure out how to make the copy command accept a variable for ... Until the echo is ... > The pause alloes you to revise the output. ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: Simple Unix script..but goes awry
    ... > log file into an Oracle db. ... > echo $FILE1 ... > cat tmp.sql ... Are you sure it's not the "echo" command that's doing that? ...
    (comp.unix.shell)
  • Re: Persisting env vars in cmd windows
    ... more about batch files as you go on, ... echo The time is %time::=.% ... But the piece de resistance was the "start" command, ... echo:: ERROR ERROR ERROR ERROR ...
    (microsoft.public.win2000.general)
  • Re: Persisting env vars in cmd windows
    ... But the piece de resistance was the "start" command, ... - Have all code for the one project in one single batch file. ... @echo off ... echo:: ERROR ERROR ERROR ERROR ...
    (microsoft.public.win2000.general)
  • Re: Persisting env vars in cmd windows
    ... even though it applies to any command, e.g. echo, copy, ... Similarly the syntax for the extremely powerful "for" command ... more about batch files as you go on, ... echo:: ERROR ERROR ERROR ERROR ...
    (microsoft.public.win2000.general)