Find keyword in file type "Lookup table" in DOS

1

I am trying to create a batch script (Windows console) that analyzes a flat text file style "lookup table" which contains a series of lines in "PALABRA_CLAVE VALOR" format.

I have problems checking with the command find or findstr if the keyword already exists in that file .

Suppose there is a keyword "SECOND_ENTRY" and you want to check if "SECOND" exists to create it as a new key.

Since find detects that this keyword already exists, but this is not true, there is simply another one that contains that string, but it is not that string specifically.

So, I'm looking for a solution to analyze the exact string as it goes before the first space.

Reading a bit the help, I tried with the / X modifier, but this one analyzes the whole line, so it is not valid for this case, and then there is the / C that seemed to be the solution, since the statement says that analyzes the string literally, but I can not get it to work, I just get it to say "operator / C has been omitted".

I leave an example of the code below:

findstr /C "%KEY%" %FILE%>null
IF %errorlevel% EQU 0 (
echo ERROR! The provided KEY already exists in the FILE! please, Insert a new one.

The LOOKUP style file:

FIRST_ENTRY this is a sample for the first entry
SECOND_ENTRY another entry for our ets
THIRD_ENTRY blah blah blaaah
FOURTH_ENTRY jdajhsdjhsad
FIFTH ???
NEW_ENTRY this is the value
    
asked by scripter_novato 22.03.2018 в 10:07
source

1 answer

1

Okay, I answer to myself, I have already discovered where the fault was.

Instead of:

findstr /C "%KEY%" %FILE%>null

It's like this:

findstr /c:"%KEY% " "..\%FILE%">null

By doing this, the / C switch does not fail and the keyword can be detected only.

    
answered by 22.03.2018 в 12:42