Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 在表中查找字符串并返回值_Windows_Command Line_Cmd_Findstr - Fatal编程技术网

Windows 在表中查找字符串并返回值

Windows 在表中查找字符串并返回值,windows,command-line,cmd,findstr,Windows,Command Line,Cmd,Findstr,想象一下这个.txt文件: Example.txt Row Column1 Column2 Column3 <br> 1 aaa bbb ccc<br> 2 ddd eee fff Example.txt 第1列第2列第3列 1 aaa bbb ccc 2 ddd eee fff 如何使用命令行获取表中的值 示例:(行=2,列2)返回值“eee”。 例如:(行=1,

想象一下这个
.txt
文件:

Example.txt

Row    Column1    Column2    Column3 <br>
1       aaa         bbb        ccc<br>
2       ddd         eee        fff
Example.txt
第1列第2列第3列
1 aaa bbb ccc
2 ddd eee fff
如何使用命令行获取表中的值

示例:(行=2,列2)返回值“eee”。
例如:(行=1,列3)返回值“ccc”


我正在尝试
findstr
,但我不知道如何实现它。

假设行信息实际上在文件中,并且假设没有包含空格的值:

@echo off
call :getValue  2  Column2  "Example.txt"
call :getValue  1  Column3  "Example.txt"
call :getValue  0  Column1  "Example.txt"
call :getValue  1  DoesNotExist  "Example.txt"
exit /b

:getValue
setlocal
<%3 set /p "header="
set token=0
for %%C in (%header%) do (
  set /a token+=1
  if %%C==%2 goto columnFound
)
echo Column %2 not found in %3
exit /b

:columnFound
for /f "tokens=%token%" %%A in ('findstr /blc:"%1 " %3') do (
  echo %3 (Row=%1, %2^) = %%A
  exit /b
)
echo Row %1 not found in %3
exit /b

文件中的行号信息在物理上是否作为第一列?
"Example.txt" (Row=2, Column2) = eee
"Example.txt" (Row=1, Column3) = ccc
Row 0 not found in "Example.txt"
Column DoesNotExist not found in "Example.txt"