本文介绍了Findstr在1个文件上并将变量输出到outfile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对脚本世界很陌生。我想知道你是否可以帮助我。

I am quite new to the scripting world. I am wondering if you could help me out here.

我在一个目录(InFile)中有一个文件,需要将它们与一个类似于Excel的vlookup的文件进行比较( CompareFile)。

I have a file in a directory (InFile) and would need to compare them to a file similar to what Excel's vlookup is for (CompareFile).

InFile中的每一行都有多个令牌,它们由","分隔。我只对将令牌#1和#3与CompareFile进行比较感兴趣。我们假设令牌#1 = My_date和令牌#3 = My_customer。

Each line in InFile has multiple tokens and they are delimited by ",". I am only interested in comparing token # 1 and # 3 with the CompareFile. Let's assume token #1 = My_date and token #3 = My_customer.

CompareFile具有My_date,My_customer和Customer_Address的布局。

CompareFile has layout of My_date, My_customer and Customer_Address.

我正在尝试编写一个批处理文件,该文件将读取InFile,然后查找其上包含令牌#1和#3的任何行,然后使用令牌#1,#3和CustomerAddress将其输出到OutFile。 (我无法使用"tokens = 1,3
delim ="提取标记#1和#3,所以我修改了它以从整行中提取子字符串。

I am trying to write a batch file that would read the InFile and then find any lines that have both token #1 and #3 on it, and then output it to OutFile with token #1, #3 and the CustomerAddress. (I wasn't able to extract tokens #1 and #3 using the "tokens=1,3 delim=," so I have modified it to extract a substring from the whole line.

我目前有以下代码,但它不会为我生成outfile而且我不知道为什么。你介意指点我正确的方向吗?谢谢。

I currently have the following codes but it's not producing the outfile for me and I don't know why. Would you mind pointing me to the right direction please? Thanks.

SET InFile = InFile.csv

FOR / F %% A IN(%InFile%)DO CALL:FindString" %% A"

pause

GOTO:eof

SET InFile=InFile.csv
FOR /F %%A IN (%InFile%) DO CALL :FindString "%%A"
pause
GOTO :eof

:FindString

SET my_filename =%1

/ f" delims = " %% x in(%my_filename)do



set my_str = %% x

set my_timestamp =%my_str:~0 ,18%

设置my_cmts =%my_str:~25,12%

findstr /irc:%my_timestamp%.*%my_cmts%  CompareFile echo> OutFile

:FindString
SET my_filename=%1
for /f "delims=" %%x in (%my_filename) do
(
set my_str=%%x
set my_timestamp=%my_str:~0,18%
set my_cmts=%my_str:~25,12%
findstr /irc:%my_timestamp%.*%my_cmts%  CompareFile echo > OutFile

暂停



暂停

GOTO:eof

pause
)
pause
GOTO :eof

推荐答案


这篇关于Findstr在1个文件上并将变量输出到outfile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 19:54