computing
  • 0

How Do I Output The First Word In Text file?

  • 0

i’m trying to write a batch file that sets a variable to the first word in a text file.
i can get it to find the first word in the text file using the findstr command, but it outputs the entire line, this is what i have so far:

@echo off
for /f “tokens=*” %%a in (‘findstr /b /i “\<.*\>” “%cd%\somthing.txt”‘) do set a=%%a
echo %a%
pause

but even though it is picking up on the first word, it outputs the whole line, and i can’t find any commands to make it output just the first word.
does anyone have an idea of how to make this output the first word? or possibly even a completely new command to do so. thanks a heap for any suggestions 🙂

Share

1 Answer

  1. The first “word” in the file:

    @echo off
    for /f "usebackq" %%a in ( "filename" ) do (
        set a=%%a
        goto done
    )
    :done
    echo %a%
    pause
    

    • 0