-1

data.txt = Hamza,Rayss,male,fr_FR


@echo off
set /P "userString=Enter the search string: "
for /f "delims=" %%i in ('type "data.txt" ^|findstr /i /r "%userString%"') do Cls &Color 0a &echo %%i
pause >null

I want the result like this

  1. Nom : Hamza
  2. Prenom : Rayss
  3. Sx : male
  4. py : fr_FR
  • 2
    Open a Command Prompt window, type `for /?` and press the `[ENTER]` key, and read the usage information within the `FOR /F` section. Pay particular attention to the `tokens` and `delims` part. We are not here to tell you how to do something which is explained within the built-in command help, or used on this site tens of thousands of times already. – Compo Jun 02 '22 at 01:15
  • `%SystemRoot%\System32\findstr.exe /I /C:"%userString%" "data.txt"` outputs all lines containing the literally, case-insensitive searched string in file `data.txt` in the current directory whatever the current directory is on running __FINDSTR__. As the data text file does not contain the strings `Nom :`, `Prenom :`, `Sx :` and `py :`, you may need to capture the output with `for /F`, split up the line into four tokens (substrings) using the comma as string delimiter and output the four substrings with four `echo` command lines inside the __FOR__ loop. – Mofi Jun 02 '22 at 05:58
  • I recommend to read also the chapter about `set /P` in my answer on [How to stop Windows command interpreter from quitting batch file execution on an incorrect user input?](https://stackoverflow.com/a/49834019/3074564) to make the user prompt fail-safe and secure on execution of the batch file. – Mofi Jun 02 '22 at 06:00

0 Answers0