Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Findstr on 1 file and outputting variables to an outfile

$
0
0

Hi,

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

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).

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 has layout of My_date, My_customer and Customer_Address.

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.

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

: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

pause
)
pause
GOTO :eof




Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>